MCPcopy Create free account
hub / github.com/dmtcp/dmtcp / doConnect

Function doConnect

test/frisbee.cpp:102–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102void
103doConnect(int &connectSock, hostent *host, int port, const char *hostname)
104{
105 sockaddr_in addr;
106
107 memset(&addr, 0, sizeof(addr));
108 addr.sin_family = AF_INET;
109 memcpy(&addr.sin_addr.s_addr, host->h_addr, host->h_length);
110 addr.sin_port = htons(port);
111 int fd = -1;
112 for (size_t i = 0; i < 20; i++) {
113 fd = connect(connectSock, (sockaddr *)&addr, sizeof(addr));
114 if (fd != -1) {
115 break;
116 }
117
118 // Sleep for 100 ms to allow the other process to do a bind.
119 struct timespec t;
120 t.tv_sec = 0;
121 t.tv_nsec = 100 * 1000 * 1000;
122 nanosleep(&t, NULL);
123 }
124
125 // If connect fails even after 20 tries, give up.
126 assert(fd >= 0);
127}

Callers 1

mainFunction · 0.85

Calls 3

memsetFunction · 0.85
memcpyFunction · 0.85
connectFunction · 0.50

Tested by

no test coverage detected