FACT++  1.0
bool READ_STRUCT::check ( int  sockDef,
sockaddr_in  addr 
)

Definition at line 366 of file EventBuilder.cc.

References factPrintf(), MessageImp::kError, kHeader, MessageImp::kInfo, kStream, and MAX_LEN.

367 {
368  // Continue in the most most likely case (performance)
369  //if (socket>=0 && sockDef!=0 && connected)
370  // return;
371  const int old = socket;
372 
373  // socket open, but should not be open
374  if (socket>=0 && sockDef==0)
375  destroy();
376 
377  // Socket closed, but should be open
378  if (socket<0 && sockDef!=0)
379  create(addr); //generate address and socket
380 
381  const bool retval = old!=socket;
382 
383  // Socket closed
384  if (socket<0)
385  return retval;
386 
387  // Socket open and connected: Nothing to do
388  if (connected)
389  return retval;
390 
391  //try to connect if not yet done
392  const int rc = connect(socket, (struct sockaddr *) &SockAddr, sizeof(SockAddr));
393  if (rc == -1)
394  return retval;
395 
396  connected = true;
397 
398  if (sockDef<0)
399  {
400  bufTyp = READ_STRUCT::kStream; // full data to be skipped
401  bufLen = MAX_LEN; // huge for skipping
402  }
403  else
404  {
405  bufTyp = READ_STRUCT::kHeader; // expect a header
406  bufLen = sizeof(PEVNT_HEADER); // max size to read at begining
407  }
408 
409  bufPos = B; // no byte read so far
410  skip = 0; // start empty
411  totBytes = 0;
412  relBytes = 0;
413 
414  factPrintf(MessageImp::kInfo, "Connected socket %d (%d)", sockId, socket);
415 
416 #ifdef USE_EPOLL
417  epoll_event ev;
418  ev.events = EPOLLIN;
419  ev.data.ptr = this; // user data (union: ev.ptr)
420  if (epoll_ctl(fd_epoll, EPOLL_CTL_ADD, socket, &ev)<0)
421  factPrintf(MessageImp::kError, "epoll_ctl failed: %m (EPOLL_CTL_ADD,rc=%d)", errno);
422 #endif
423 
424  return retval;
425 }
void factPrintf(int severity, const char *fmt,...)
uint8_t * bufPos
uint64_t totBytes
uint32_t bufLen
uint64_t relBytes
An info telling something which can be interesting to know.
Definition: MessageImp.h:17
bool create(sockaddr_in addr)
void destroy()
uint8_t B[MAX_LEN]
struct sockaddr_in SockAddr
Error, something unexpected happened, but can still be handled by the program.
Definition: MessageImp.h:19
buftyp_t bufTyp
static int fd_epoll
#define MAX_LEN
Definition: EventBuilder.cc:22
uint32_t skip

+ Here is the call graph for this function: