server 0.0.1
basicserverinfrastructure

src/socket/accept.c

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