add timeout to close inactive connections
This commit is contained in:
parent
2aa468369f
commit
6b62d31dc5
1 changed files with 7 additions and 0 deletions
7
fbflut.c
7
fbflut.c
|
@ -6,6 +6,7 @@
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <linux/fb.h>
|
#include <linux/fb.h>
|
||||||
|
@ -70,6 +71,7 @@ void *handle_connection(void *socket_desc) {
|
||||||
memset(client_message, 0, 36);
|
memset(client_message, 0, 36);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(sock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,6 +116,11 @@ int main(int argc, char *argv[]) {
|
||||||
server.sin_addr.s_addr = INADDR_ANY;
|
server.sin_addr.s_addr = INADDR_ANY;
|
||||||
server.sin_port = htons(port);
|
server.sin_port = htons(port);
|
||||||
|
|
||||||
|
struct timeval tv;
|
||||||
|
tv.tv_sec = 60;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
setsockopt(socket_desc, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof tv);
|
||||||
|
|
||||||
if (bind(socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0)
|
if (bind(socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0)
|
||||||
return 15;
|
return 15;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue