librnr/sock.c
Socket_T *SocketAccept(Socket_T *pSocketListener, bool_t bNonBlock)
{
	int									sd;
  struct sockaddr     saddr;
  unsigned int        addrlen = sizeof(saddr);
  Socket_T           *pSocket;

	LOGDIAG4CALL("pSocketListener->%s", pSocketListener->m_sLocalName);

  // accept incoming connection
  if((sd = accept(pSocketListener->m_sd, &saddr, (socklen_t *)&addrlen)) == -1)
  {
		LOGSYSERROR("accept(%d,...)", pSocketListener->m_sd);
    return NULL;
  }

  //
  // Now create a new socket and set the appropriate attributes
  //
  pSocket = SocketNew();

  SocketAttrSetSd(pSocket, sd);
  SocketAttrSetPort(pSocket, ((struct sockaddr_in*)&saddr)->sin_port);
  SocketAttrSetFlavor(pSocket, 
      SockFlavorDomainIPv4|SockFlavorProtocolTcp|SockFlavorFuncConnection);
  SocketAttrSetLocalName(pSocket, NULL);
  SocketAttrSetRemoteName(pSocket, &saddr, NULL); 

  // set non-blocking
  if( bNonBlock )
  {
    if( SocketAttrSetNonBlocking(pSocket) == -1 )
    {
		  LOGERROR("SockAttrSetNonBlocking() failed");
      SocketClose(pSocket);
      SocketDelete(pSocket);
      return NULL;
    }
  }

  LOGDIAG4("Accepted connection from %s", SocketAttrGetRemoteName(pSocket));

	return pSocket;
}
/*!
 * \brief Accept a client connection requst from the listener socket.
 *
 * The new socket will be set to non-blocking I/O mode if requested.
 *
 * \param pSocketListener Pointer to open listener socket.
 * \param  bNonBlock      Do [not] set socket to non-blocking.
 *
 * Return Value:
 *  Newly allocated and accepted open Socket_T pointer on success,
 *  NULL on failure.
 */
\brief Accept a client connection requst from the listener socket.
The new socket will be set to non-blocking I/O mode if requested.

\param pSocketListener Pointer to open listener socket.
\param  bNonBlock      Do [not] set socket to non-blocking.

Return Value:
Newly allocated and accepted open Socket_T pointer on success,
NULL on failure.
\ brief Accept a client connection requst from the listener socket . The new socket will be set to non - blocking I / O mode if requested . \ param pSocketListener Pointer to open listener socket . \ param bNonBlock Do [ not ] set socket to non - blocking . Return Value : Newly allocated and accepted open Socket_T pointer on success NULL on failure .
Socket_T *SocketAccept(Socket_T *pSocketListener, bool_t bNonBlock)
{
	int									sd;
  struct sockaddr     saddr;
  unsigned int        addrlen = sizeof(saddr);
  Socket_T           *pSocket;
	LOGDIAG4CALL("pSocketListener->%s", pSocketListener->m_sLocalName);
  if((sd = accept(pSocketListener->m_sd, &saddr, (socklen_t *)&addrlen)) == -1)
  {
		LOGSYSERROR("accept(%d,...)", pSocketListener->m_sd);
    return NULL;
  }
   Now create a new socket and set the appropriate attributes
  pSocket = SocketNew();
  SocketAttrSetSd(pSocket, sd);
  SocketAttrSetPort(pSocket, ((struct sockaddr_in*)&saddr)->sin_port);
  SocketAttrSetFlavor(pSocket, 
      SockFlavorDomainIPv4|SockFlavorProtocolTcp|SockFlavorFuncConnection);
  SocketAttrSetLocalName(pSocket, NULL);
  SocketAttrSetRemoteName(pSocket, &saddr, NULL); 
   set non-blocking
  if( bNonBlock )
  {
    if( SocketAttrSetNonBlocking(pSocket) == -1 )
    {
		  LOGERROR("SockAttrSetNonBlocking() failed");
      SocketClose(pSocket);
      SocketDelete(pSocket);
      return NULL;
    }
  }
  LOGDIAG4("Accepted connection from %s", SocketAttrGetRemoteName(pSocket));
	return pSocket;
}
Socket_T * SocketAccept ( Socket_T * pSocketListener , bool_t bNonBlock ) { int sd ; struct sockaddr saddr ; unsigned int addrlen = sizeof ( saddr ) ; Socket_T * pSocket ; LOGDIAG4CALL ( " " , pSocketListener -> m_sLocalName ) ; if ( ( sd = accept ( pSocketListener -> m_sd , & saddr , ( socklen_t * ) & addrlen ) ) == -1 ) { LOGSYSERROR ( " " , pSocketListener -> m_sd ) ; return NULL ; } pSocket = SocketNew ( ) ; SocketAttrSetSd ( pSocket , sd ) ; SocketAttrSetPort ( pSocket , ( ( struct sockaddr_in * ) & saddr ) -> sin_port ) ; SocketAttrSetFlavor ( pSocket , SockFlavorDomainIPv4 | SockFlavorProtocolTcp | SockFlavorFuncConnection ) ; SocketAttrSetLocalName ( pSocket , NULL ) ; SocketAttrSetRemoteName ( pSocket , & saddr , NULL ) ; if ( bNonBlock ) { if ( SocketAttrSetNonBlocking ( pSocket ) == -1 ) { LOGERROR ( " " ) ; SocketClose ( pSocket ) ; SocketDelete ( pSocket ) ; return NULL ; } } LOGDIAG4 ( " " , SocketAttrGetRemoteName ( pSocket ) ) ; return pSocket ; }
\brief Accept a client connection requst from the listener socket.
\ brief Accept a client connection requst from the listener socket .
// accept incoming connection // // Now create a new socket and set the appropriate attributes // // set non-blocking