|
Server 0.0.1
HTTP/REST server implementation
|
00001 00023 #include <errno.h> // for errno 00024 #include <unistd.h> 00025 00026 #include "socket.h" 00027 #include "class.h" 00028 #include "logger.h" 00029 00030 Sock 00031 socketAccept(Sock this, char (*remoteAddr)[16]) 00032 { 00033 Sock sock; // Socket for client 00034 unsigned int len; // Length of client address data structure 00035 00036 // Set the size of the in-out parameter 00037 len = sizeof(this->addr); 00038 00046 sock = new(Sock, this->log, -1); 00047 00048 // Wait for a client to connect 00049 sock->handle = accept(this->handle, (struct sockaddr *) &(sock->addr), &len); 00050 if (-1 == sock->handle) { 00051 loggerLog(this->log, LOGGER_WARNING, 00052 "error accepting connection: %s", strerror(errno)); 00053 } else { 00054 strcpy(*remoteAddr, inet_ntoa((sock->addr).sin_addr)); 00055 00056 loggerLog(this->log, LOGGER_INFO, 00057 "handling client %s\n", inet_ntoa((sock->addr).sin_addr)); 00058 } 00059 00060 return sock; 00061 } 00062 00063 // vim: set ts=4 sw=4: