fixed http request hangup and socket usage
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
DesignedWorlds
BIN
DesignedWorlds
Binary file not shown.
@@ -8,6 +8,8 @@
|
||||
#ifndef HTTP_H
|
||||
#define HTTP_H
|
||||
|
||||
#define HTTP_PORT 9090
|
||||
|
||||
#define HTTP_UNKNOWN 0
|
||||
#define HTTP_GET 1
|
||||
#define HTTP_POST 2
|
||||
|
||||
@@ -46,11 +46,17 @@ void handleClient(int sock) {
|
||||
memcpy(packetBuilder, tmp, tmpSize);
|
||||
free(tmp);
|
||||
memcpy(&packetBuffer[tmpSize], packetBuilder, sizeOfPacket);
|
||||
if(sizeOfPacket < HTTP_RECIVE_PACKET_SIZE) {
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
memcpy(packetBuffer, packetBuilder, sizeOfPacket);
|
||||
if(sizeOfPacket < HTTP_RECIVE_PACKET_SIZE) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if(sizeOfPacket < 0) {
|
||||
exit(-1);
|
||||
}
|
||||
@@ -106,10 +112,12 @@ int main() {
|
||||
perror("socket");
|
||||
return -1;
|
||||
}
|
||||
int opts = 1;
|
||||
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opts, sizeof(opts));
|
||||
|
||||
struct sockaddr_in addr;
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(9091);
|
||||
addr.sin_port = htons(HTTP_PORT);
|
||||
inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
|
||||
|
||||
if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
|
||||
Reference in New Issue
Block a user