This commit is contained in:
Xuan Sang LE 2018-05-03 15:10:44 +02:00
parent 6daf67c908
commit 8618c9ebf5
3 changed files with 30 additions and 6 deletions

12
httpd.c
View File

@ -239,6 +239,18 @@ int main(int argc, char* argv[])
} }
//return &(((struct sockaddr_in6*)sa)->sin6_addr); //return &(((struct sockaddr_in6*)sa)->sin6_addr);
/* accept_request(client_sock); */ /* accept_request(client_sock); */
// set timeout to socket
struct timeval timeout;
timeout.tv_sec = 20;
timeout.tv_usec = 0;
if (setsockopt (client_sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,sizeof(timeout)) < 0)
perror("setsockopt failed\n");
if (setsockopt (client_sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout,sizeof(timeout)) < 0)
perror("setsockopt failed\n");
client->sock = client_sock; client->sock = client_sock;
server_config.connection++; server_config.connection++;
//LOG("Unclosed connection: %d\n", server_config.connection); //LOG("Unclosed connection: %d\n", server_config.connection);

View File

@ -72,38 +72,50 @@ int response(void* client, const char* data)
int antd_send(const void *src, const void* data, int len) int antd_send(const void *src, const void* data, int len)
{ {
if(!src || !data) return -1; if(!src || !data) return -1;
int ret;
antd_client_t * source = (antd_client_t *) src; antd_client_t * source = (antd_client_t *) src;
#ifdef USE_OPENSSL #ifdef USE_OPENSSL
if(usessl()) if(usessl())
{ {
//LOG("SSL WRITE\n"); //LOG("SSL WRITE\n");
return SSL_write((SSL*) source->ssl, data, len); ret = SSL_write((SSL*) source->ssl, data, len);
} }
else else
{ {
#endif #endif
return send(source->sock, data, len, 0); ret = send(source->sock, data, len, 0);
#ifdef USE_OPENSSL #ifdef USE_OPENSSL
} }
#endif #endif
if(ret <= 0)
{
antd_close(src);
}
return ret;
} }
int antd_recv(const void *src, void* data, int len) int antd_recv(const void *src, void* data, int len)
{ {
if(!src) return -1; if(!src) return -1;
int ret;
antd_client_t * source = (antd_client_t *) src; antd_client_t * source = (antd_client_t *) src;
#ifdef USE_OPENSSL #ifdef USE_OPENSSL
if(usessl()) if(usessl())
{ {
//LOG("SSL READ\n"); //LOG("SSL READ\n");
return SSL_read((SSL*) source->ssl, data, len); ret = SSL_read((SSL*) source->ssl, data, len);
} }
else else
{ {
#endif #endif
return recv(((int) source->sock), data, len, 0); ret = recv(((int) source->sock), data, len, 0);
#ifdef USE_OPENSSL #ifdef USE_OPENSSL
} }
#endif #endif
if(ret == 0)
{
antd_close(src);
}
return ret;
} }
int antd_close(void* src) int antd_close(void* src)
{ {

View File

@ -77,7 +77,7 @@ void unknow(void*);
int ws_enable(dictionary); int ws_enable(dictionary);
char* read_line(void* sock); char* read_line(void* sock);
int read_buf(void* sock,char* buf,int i); int read_buf(void* sock,char* buf,int i);
int antd_send(const void *source, const void* data, int len); int antd_send( void *source, const void* data, int len);
int antd_recv(const void *source, void* data, int len); int antd_recv( void *source, void* data, int len);
int antd_close(void* source); int antd_close(void* source);
#endif #endif