return -1;
}
-static int send_data_to_server(struct fireperf_config* conf,
- struct fireperf_stats* stats, int fd) {
- const char* buffer = ZERO;
- ssize_t bytes_sent;
-
- if (conf->pool) {
- buffer = fireperf_random_pool_get_slice(conf->pool, SOCKET_SEND_BUFFER_SIZE);
- }
-
- do {
- bytes_sent = send(fd, buffer, SOCKET_SEND_BUFFER_SIZE, 0);
- } while (bytes_sent < 0 && (errno == EAGAIN || errno == EWOULDBLOCK));
-
- DEBUG(conf, "bytes_sent = %zu\n", bytes_sent);
-
- // Update statistics
- stats->bytes_sent += bytes_sent;
- stats->total_bytes_sent += bytes_sent;
-
- return 0;
-}
-
static int handle_connection_ready(struct fireperf_config* conf,
struct fireperf_stats* stats, int fd) {
// Are we supposed to close this connection straight away?
return 0;
}
- return send_data_to_server(conf, stats, fd);
+ return handle_connection_send(conf, stats, fd);
}
int fireperf_client(struct fireperf_config* conf, struct fireperf_stats* stats,
return 0;
}
+
+int handle_connection_send(struct fireperf_config* conf,
+ struct fireperf_stats* stats, int fd) {
+ const char* buffer = ZERO;
+ ssize_t bytes_sent;
+
+ if (conf->pool) {
+ buffer = fireperf_random_pool_get_slice(conf->pool, SOCKET_SEND_BUFFER_SIZE);
+ }
+
+ do {
+ bytes_sent = send(fd, buffer, SOCKET_SEND_BUFFER_SIZE, 0);
+ } while (bytes_sent < 0 && (errno == EAGAIN || errno == EWOULDBLOCK));
+
+ // Update statistics
+ stats->bytes_sent += bytes_sent;
+ stats->total_bytes_sent += bytes_sent;
+
+ return 0;
+}
+
+int handle_connection_recv(struct fireperf_config* conf,
+ struct fireperf_stats* stats, int fd) {
+ char buffer[SOCKET_RECV_BUFFER_SIZE];
+ ssize_t bytes_read;
+
+ // Try reading into buffer
+ do {
+ bytes_read = recv(fd, buffer, sizeof(buffer), 0);
+ } while (bytes_read < 0 && (errno == EAGAIN || errno == EWOULDBLOCK));
+
+ // Error?
+ if (bytes_read < 0) {
+ ERROR(conf, "Could not read from socket %d: %s\n", fd, strerror(errno));
+ return -1;
+ }
+
+ DEBUG(conf, "Read %zu bytes from socket %d\n", bytes_read, fd);
+
+ // Update statistics
+ stats->bytes_received += bytes_read;
+ stats->total_bytes_received += bytes_read;
+
+ return 0;
+}
int fireperf_dump_stats(struct fireperf_config* conf, struct fireperf_stats* stats, int mode);
+int handle_connection_send(struct fireperf_config* conf,
+ struct fireperf_stats* stats, int fd);
+int handle_connection_recv(struct fireperf_config* conf,
+ struct fireperf_stats* stats, int fd);
+
#endif /* FIREPERF_MAIN_H */
return fd;
}
-static int handle_io_on_connection(struct fireperf_config* conf,
- struct fireperf_stats* stats, int fd) {
- char buffer[SOCKET_RECV_BUFFER_SIZE];
- ssize_t bytes_read;
-
- // Try reading into buffer
- do {
- bytes_read = recv(fd, buffer, sizeof(buffer), 0);
- } while (bytes_read < 0 && (errno == EAGAIN || errno == EWOULDBLOCK));
-
- // Error?
- if (bytes_read < 0) {
- ERROR(conf, "Could not read from socket %d: %s\n", fd, strerror(errno));
- return -1;
- }
-
- DEBUG(conf, "Read %zu bytes from socket %d\n", bytes_read, fd);
-
- // Update statistics
- stats->bytes_received += bytes_read;
- stats->total_bytes_received += bytes_read;
-
- return 0;
-}
-
static int is_listening_socket(struct fireperf_config* conf, int* sockets, int fd) {
for (unsigned int i = 0; i < conf->listening_sockets; i++) {
if (sockets[i] == fd)
// One of the connections had IO
if (events[i].events & EPOLLIN) {
- r = handle_io_on_connection(conf, stats, fd);
+ r = handle_connection_recv(conf, stats, fd);
if (r < 0)
goto ERROR;
}