FACT++  1.0
bool READ_STRUCT::create ( sockaddr_in  addr)

Definition at line 297 of file EventBuilder.cc.

References factPrintf(), MessageImp::kFatal, and MessageImp::kInfo.

298 {
299  if (socket>=0)
300  return false;
301 
302  const int port = ntohs(sockAddr.sin_port) + 1;
303 
304  SockAddr.sin_family = sockAddr.sin_family;
305  SockAddr.sin_addr = sockAddr.sin_addr;
306  SockAddr.sin_port = htons(port);
307 
308  if ((socket = ::socket(PF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0)) <= 0)
309  {
310  factPrintf(MessageImp::kFatal, "Generating socket %d failed: %m (socket,rc=%d)", sockId, errno);
311  socket = -1;
312  return false;
313  }
314 
315  int optval = 1;
316  if (setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, &optval, sizeof(int)) < 0)
317  factPrintf(MessageImp::kInfo, "Setting TCP_NODELAY for socket %d failed: %m (setsockopt,rc=%d)", sockId, errno);
318 
319  optval = 1;
320  if (setsockopt (socket, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(int)) < 0)
321  factPrintf(MessageImp::kInfo, "Setting SO_KEEPALIVE for socket %d failed: %m (setsockopt,rc=%d)", sockId, errno);
322 
323  optval = 10; //start after 10 seconds
324  if (setsockopt (socket, SOL_TCP, TCP_KEEPIDLE, &optval, sizeof(int)) < 0)
325  factPrintf(MessageImp::kInfo, "Setting TCP_KEEPIDLE for socket %d failed: %m (setsockopt,rc=%d)", sockId, errno);
326 
327  optval = 10; //do every 10 seconds
328  if (setsockopt (socket, SOL_TCP, TCP_KEEPINTVL, &optval, sizeof(int)) < 0)
329  factPrintf(MessageImp::kInfo, "Setting TCP_KEEPINTVL for socket %d failed: %m (setsockopt,rc=%d)", sockId, errno);
330 
331  optval = 2; //close after 2 unsuccessful tries
332  if (setsockopt (socket, SOL_TCP, TCP_KEEPCNT, &optval, sizeof(int)) < 0)
333  factPrintf(MessageImp::kInfo, "Setting TCP_KEEPCNT for socket %d failed: %m (setsockopt,rc=%d)", sockId, errno);
334 
335  factPrintf(MessageImp::kInfo, "Generated socket %d (%d)", sockId, socket);
336 
337  //connected = false;
338  activeSockets++;
339 
340  return true;
341 }
void factPrintf(int severity, const char *fmt,...)
An info telling something which can be interesting to know.
Definition: MessageImp.h:17
static uint activeSockets
struct sockaddr_in SockAddr
An error which cannot be handled at all happend, the only solution is program termination.
Definition: MessageImp.h:21

+ Here is the call graph for this function: