Project

General

Profile

Revision 14

Added by Jason knichel over 16 years ago

added a write function to the connection pool

View differences:

trunk/code/projects/colonet/ColonetServer/client.cpp
45 45
      int value = (int)(pkt->data[0]);
46 46
      snprintf(buffer, WRITE_BUFFER_SIZE, "%d\n", value);
47 47
          
48
      //TODO:make a connection pool write function and move this code into it
49 48
      int len = strlen(buffer);
50
      if (len > (WRITE_BUFFER_SIZE-connection_pool.get_write_buffer_size(dest)))
51
      {
52
        printf("There is not enough room in the write buffer to send the data to the client.\n");
53
        return -1;
54
      }
55

  
56
      memcpy(connection_pool.get_write_buffer(dest), buffer, len);
57
      connection_pool.set_write_buffer_size(dest, len);
49
      connection_pool.write_to_client(dest, buffer, len);
58 50
      printf("Put data in write buffer for client.\n");
59 51
    }
60 52
    else
trunk/code/projects/colonet/ColonetServer/includes/ConnectionPool.h
31 31
  int add_client(int client_file_descriptor);
32 32
  int remove_client(int client_file_descriptor);
33 33
  int check_clients();
34
  int write_to_client(int pool_index, char * message, int length);
34 35
  void set_listen_socket_in_ready_set(int listen_socket);
35 36
  int perform_select(int listen_socket, struct timeval * select_timeout);
36 37
  int is_socket_ready_to_read(int socket);
......
53 54
  fd_set get_write_set();
54 55
  void set_write_set(fd_set new_set);
55 56

  
56
  int get_write_buffer_size(int pool_index);
57
  void set_write_buffer_size(int pool_index, int new_buffer_size);
58

  
59
  char * get_write_buffer(int pool_index);
60

  
61

  
62 57
private:
63 58
  int max_file_descriptor;
64 59
  int next_available_slot;
trunk/code/projects/colonet/ColonetServer/ConnectionPool.cpp
219 219
  return 0;
220 220
}
221 221

  
222
int ConnectionPool::write_to_client(int pool_index, char * message, int length) {
223
  //TODO: put error checking on pool_index, message, length
224
  if (length > (WRITE_BUFFER_SIZE-write_buffer_size[pool_index]))
225
    {
226
      //TODO: make this a logging statement instead of a print statement
227
      printf("There is not enough room in the write buffer to send the data to the client.\n");
228
      return -1;
229
    }
222 230

  
231
  memcpy(write_buffer[pool_index], message, length);
232
  write_buffer_size[pool_index] += length;
233

  
234
  return 0;
235
}
236

  
237

  
223 238
//TODO: put error checking on listen_socket to make sure its a valid socket
224 239
void ConnectionPool::set_listen_socket_in_ready_set(int listen_socket) {
225 240
  FD_SET(listen_socket, &ready_set);
......
286 301
  write_set = new_set;
287 302
}
288 303

  
289
//TODO: remove after a write_to_client or similar method is written so this won't be needed anymore
290
int ConnectionPool::get_write_buffer_size(int pool_index) {
291
  return write_buffer_size[pool_index];
292
}
293

  
294
//TODO: remove after a write_to_client or similar method is written so this won't be needed anymore
295
void ConnectionPool::set_write_buffer_size(int pool_index, int new_buffer_size) {
296
  write_buffer_size[pool_index] = new_buffer_size;
297
}
298

  
299
//TODO: remove after a write_to_client or similar method is written so this won't be needed anymore
300
char * ConnectionPool::get_write_buffer(int pool_index) {
301
  return write_buffer[pool_index];
302
}
303

  
304 304
//TODO: write a function to write data into the write buffers
305 305
//TODO: fix names of variables to obey new style
306 306
int ConnectionPool::parse_command(char* command, int pool_index) {

Also available in: Unified diff