This starts the program in server mode which makes it connect to the specified
port and waits for clients to connect.
+--keepalive::
+-k::
+ Instead of sending data, this will configure fireperf to only send keepalive
+ packets.
+ +
+ If a large number of connections is being created, it might become undesirable to
+ saturate the link between client and server. This option will send some packets to
+ keep the connection alive through for example NAT gateways.
+
== CLIENT-SPECIFIC OPTIONS
Duplex mode enables the client to send data instead of only receiving it from the
server. The same TCP connection will be used for traffic in both directions.
---keepalive::
--k::
- Instead of sending data to the server, this will configure the client to only
- send keepalive packets.
- +
- If a large number of connections is being created, it might become undesirable to
- saturate the link between client and server. This option will send some packets to
- keep the connection alive through for example NAT gateways.
-
--timeout=T::
-t T::
If set, the client will automatically terminate itself after T seconds.
#############################################################################*/
#include <errno.h>
-#include <netinet/tcp.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
if (r)
goto ERROR;
- // Enable keepalive
- int flags = 1;
- r = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&flags, sizeof(flags));
- if (r) {
- ERROR(conf, "Could not set SO_KEEPALIVE on socket %d: %s\n",
- fd, strerror(errno));
- goto ERROR;
- }
-
- // Set keepalive interval
- if (conf->keepalive_interval) {
- DEBUG(conf, "Setting keepalive interval to %d\n", conf->keepalive_interval);
-
- r = setsockopt(fd, SOL_TCP, TCP_KEEPINTVL,
- (void*)&conf->keepalive_interval, sizeof(conf->keepalive_interval));
- if (r) {
- ERROR(conf, "Could not set TCP_KEEPINTVL on socket %d: %s\n",
- fd, strerror(errno));
- goto ERROR;
- }
-
- DEBUG(conf, "Setting keepalive idle interval to %d\n", conf->keepalive_interval);
-
- flags = 1;
- r = setsockopt(fd, SOL_TCP, TCP_KEEPIDLE,
- (void*)&flags, sizeof(flags));
- if (r) {
- ERROR(conf, "Could not set TCP_KEEPIDLE on socket %d: %s\n",
- fd, strerror(errno));
- goto ERROR;
- }
- }
-
- // Set keepalive count
- if (conf->keepalive_count) {
- DEBUG(conf, "Setting keepalive count to %d\n", conf->keepalive_count);
-
- r = setsockopt(fd, SOL_TCP, TCP_KEEPCNT,
- (void*)&conf->keepalive_count, sizeof(conf->keepalive_count));
- if (r) {
- ERROR(conf, "Could not set TCP_KEEPCNT on socket %d: %s\n",
- fd, strerror(errno));
- goto ERROR;
- }
- }
-
// Connect to the server
r = connect(fd, &peer, sizeof(peer));
if (r && (errno != EINPROGRESS)) {
#############################################################################*/
#include <errno.h>
+#include <netinet/tcp.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define SOCKET_BACKLOG 1024
+static int enable_keepalive(struct fireperf_config* conf, int fd) {
+ // Enable keepalive
+ int flags = 1;
+ int r = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&flags, sizeof(flags));
+ if (r) {
+ ERROR(conf, "Could not set SO_KEEPALIVE on socket %d: %s\n",
+ fd, strerror(errno));
+ return 1;
+ }
+
+ // Set keepalive interval
+ if (conf->keepalive_interval) {
+ DEBUG(conf, "Setting keepalive interval to %d\n", conf->keepalive_interval);
+
+ r = setsockopt(fd, SOL_TCP, TCP_KEEPINTVL,
+ (void*)&conf->keepalive_interval, sizeof(conf->keepalive_interval));
+ if (r) {
+ ERROR(conf, "Could not set TCP_KEEPINTVL on socket %d: %s\n",
+ fd, strerror(errno));
+ return 1;
+ }
+
+ DEBUG(conf, "Setting keepalive idle interval to %d\n", conf->keepalive_interval);
+
+ flags = 1;
+ r = setsockopt(fd, SOL_TCP, TCP_KEEPIDLE,
+ (void*)&flags, sizeof(flags));
+ if (r) {
+ ERROR(conf, "Could not set TCP_KEEPIDLE on socket %d: %s\n",
+ fd, strerror(errno));
+ return 1;
+ }
+ }
+
+ // Set keepalive count
+ if (conf->keepalive_count) {
+ DEBUG(conf, "Setting keepalive count to %d\n", conf->keepalive_count);
+
+ r = setsockopt(fd, SOL_TCP, TCP_KEEPCNT,
+ (void*)&conf->keepalive_count, sizeof(conf->keepalive_count));
+ if (r) {
+ ERROR(conf, "Could not set TCP_KEEPCNT on socket %d: %s\n",
+ fd, strerror(errno));
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
static int create_socket(struct fireperf_config* conf, int i) {
int r;
if (r)
goto ERROR;
+ // Enable keepalive
+ if (conf->keepalive_only) {
+ r = enable_keepalive(conf, fd);
+ if (r)
+ goto ERROR;
+ }
+
struct sockaddr_in6 addr = {
.sin6_family = AF_INET6,
.sin6_port = htons(conf->port + i),