Revision 681
added possibility of global client write
ConnectionPool.cpp | ||
---|---|---|
183 | 183 |
* @brief Puts text into a write buffer that will be written to a client's file |
184 | 184 |
* descriptor sometime when the client is ready to write. |
185 | 185 |
* |
186 |
* @param pool_index Index in the pool of the client to write to |
|
186 |
* @param pool_index Index in the pool of the client to write to. -1 for global.
|
|
187 | 187 |
* @param message The message to be written |
188 | 188 |
* @param length The length of the message |
189 | 189 |
* |
190 | 190 |
* @return 0 on success, negative error code on failure |
191 | 191 |
*/ |
192 | 192 |
int ConnectionPool::write_to_client(int pool_index, char * message, int length) { |
193 |
if (pool_index < 0 || pool_index >= next_available_slot) { |
|
194 |
return ERROR_INVALID_CLIENT_ID; |
|
195 |
} |
|
196 |
|
|
197 | 193 |
if (!message) { |
198 | 194 |
return ERROR_INVALID_MESSAGE; |
199 | 195 |
} |
... | ... | |
208 | 204 |
return ERROR_NOT_ENOUGH_ROOM; |
209 | 205 |
} |
210 | 206 |
|
211 |
//printf("Connection pool: attempting to write [%s], length %i to index %i.\n", message, length, pool_index); |
|
207 |
if (pool_index == -1) { |
|
208 |
// Global message. |
|
209 |
for (int i = 0; i < number_clients_ready; i++) { |
|
210 |
memcpy(write_buffer[i], message, length); |
|
211 |
write_buffer_size[i] += length; |
|
212 |
} |
|
213 |
} else { |
|
214 |
if (pool_index < 0 || pool_index >= next_available_slot) { |
|
215 |
return ERROR_INVALID_CLIENT_ID; |
|
216 |
} |
|
212 | 217 |
|
213 |
memcpy(write_buffer[pool_index], message, length); |
|
214 |
write_buffer_size[pool_index] += length; |
|
218 |
//printf("Connection pool: attempting to write [%s], length %i to index %i.\n", message, length, pool_index); |
|
219 |
memcpy(write_buffer[pool_index], message, length); |
|
220 |
write_buffer_size[pool_index] += length; |
|
221 |
} |
|
215 | 222 |
|
216 | 223 |
return 0; |
217 | 224 |
} |
Also available in: Unified diff