server 0.0.1
basicserverinfrastructure

src/socket/accept.c

Go to the documentation of this file.
00001 #include <errno.h>      /* for errno */
00002 
00003 #include "socket.h"
00004 #include "interface/class.h"
00005 #include "interface/logger.h"
00006 
00007 Sock
00008 socketAccept(Sock this, char remoteAddr[16])
00009 {
00010     Sock         sock;   /* Socket for client */
00011     unsigned int len;    /* Length of client address data structure */
00012 
00013     /* Set the size of the in-out parameter */
00014     len = sizeof(this->addr);
00015 
00023         sock = new(Sock, this->log, this->port);
00024         close(sock->handle);
00029     /* Wait for a client to connect */
00030     sock->handle = accept(this->handle, (struct sockaddr *) &(sock->addr), &len);
00031     if (-1 == sock->handle) {
00032         loggerLog(this->log, LOGGER_WARNING,
00033                 "error accepting connection: %s", strerror(errno));
00034     } else {
00035         loggerLog(this->log, LOGGER_INFO,
00036                                 "handling client %s\n", inet_ntoa((sock->addr).sin_addr));
00037     }
00038 
00039     return sock;
00040 }
00041 
00042 // vim: set ts=4 sw=4:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines