MCPcopy Create free account
hub / github.com/esnet/iperf / iperf_connect

Function iperf_connect

src/iperf_client_api.c:420–550  ·  view source on GitHub ↗

iperf_connect -- client to server connection function */

Source from the content-addressed store, hash-verified

418
419/* iperf_connect -- client to server connection function */
420int
421iperf_connect(struct iperf_test *test)
422{
423 int opt;
424 socklen_t len;
425
426 if (NULL == test)
427 {
428 iperf_err(NULL, "No test\n");
429 return -1;
430 }
431 FD_ZERO(&test->read_set);
432 FD_ZERO(&test->write_set);
433
434 make_cookie(test->cookie);
435
436 /* Create and connect the control channel */
437 if (test->ctrl_sck < 0)
438 // Create the control channel using an ephemeral port
439 test->ctrl_sck = netdial(test->settings->domain, Ptcp, test->bind_address, test->bind_dev, 0, test->server_hostname, test->server_port, test->settings->connect_timeout);
440 if (test->ctrl_sck < 0) {
441 i_errno = IECONNECT;
442 return -1;
443 }
444
445 // set TCP_NODELAY for lower latency on control messages
446 int flag = 1;
447 if (setsockopt(test->ctrl_sck, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int))) {
448 i_errno = IESETNODELAY;
449 return -1;
450 }
451
452#if defined (HAVE_TCP_KEEPALIVE)
453 // Set Control Connection TCP Keepalive (especially useful for long UDP test sessions)
454 if (iperf_set_control_keepalive(test) < 0)
455 return -1;
456#endif //HAVE_TCP_KEEPALIVE
457
458#if defined(HAVE_TCP_USER_TIMEOUT)
459 if ((opt = test->settings->snd_timeout)) {
460 if (setsockopt(test->ctrl_sck, IPPROTO_TCP, TCP_USER_TIMEOUT, &opt, sizeof(opt)) < 0) {
461 i_errno = IESETUSERTIMEOUT;
462 return -1;
463 }
464 }
465#endif /* HAVE_TCP_USER_TIMEOUT */
466
467 if (Nwrite(test->ctrl_sck, test->cookie, COOKIE_SIZE, Ptcp) < 0) {
468 i_errno = IESENDCOOKIE;
469 return -1;
470 }
471
472 FD_SET(test->ctrl_sck, &test->read_set);
473 if (test->ctrl_sck > test->max_fd) test->max_fd = test->ctrl_sck;
474
475 len = sizeof(opt);
476 if (getsockopt(test->ctrl_sck, IPPROTO_TCP, TCP_MAXSEG, &opt, &len) < 0) {
477 test->ctrl_sck_mss = 0;

Callers 1

iperf_run_clientFunction · 0.85

Calls 6

iperf_errFunction · 0.85
make_cookieFunction · 0.85
netdialFunction · 0.85
NwriteFunction · 0.85
warningFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…