Upload files to "/"
This commit is contained in:
parent
698e5568ae
commit
cfd57bdc67
14
server.c
14
server.c
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#define PORT 8888
|
#define PORT 8888
|
||||||
#define BUFF_SIZE 2048
|
#define BUFF_SIZE 2048
|
||||||
#define MAX_CLIENTS 10
|
#define MAX_CLIENTS 45
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int fd;
|
int fd;
|
||||||
@ -41,6 +41,9 @@ int main(void) {
|
|||||||
goto ERROR_WITHOUTCLOSE;
|
goto ERROR_WITHOUTCLOSE;
|
||||||
|
|
||||||
struct timeval tv = {.tv_sec = 1, .tv_usec = 0};
|
struct timeval tv = {.tv_sec = 1, .tv_usec = 0};
|
||||||
|
if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0)
|
||||||
|
goto ERROR;
|
||||||
|
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) < 0)
|
if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) < 0)
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
|
|
||||||
@ -64,13 +67,18 @@ int main(void) {
|
|||||||
int last = 0;
|
int last = 0;
|
||||||
char buf[25];
|
char buf[25];
|
||||||
|
|
||||||
socklen_t len = sizeof(data.clients[last]);
|
socklen_t len = sizeof(data.clients[0]);
|
||||||
while (1) {
|
while (1) {
|
||||||
|
if (last <= MAX_CLIENTS) {
|
||||||
if (recvfrom(fd, buf, sizeof(buf), 0, (struct sockaddr *)&data.clients[last], &len) > 0)
|
if (recvfrom(fd, buf, sizeof(buf), 0, (struct sockaddr *)&data.clients[last], &len) > 0)
|
||||||
if (last <= MAX_CLIENTS)
|
if (!strcmp(buf, "JOIN"))
|
||||||
last++;
|
last++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
last = 0;
|
||||||
|
}
|
||||||
|
|
||||||
ERROR:
|
ERROR:
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user