X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Fserver%2Fserver.c;h=b103e836294bfc5716b2f27e2e5322c4ed88288b;hb=bc1c8c976b0ec2836f942bddd36645b44c39f18f;hp=f4b25d8677ff829d09282c894fc5f9fcb2d18493;hpb=0c56e84f2832fb407aa3492ca138615a40bad065;p=tpg%2Fopendispense2.git diff --git a/src/server/server.c b/src/server/server.c index f4b25d8..b103e83 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -23,6 +23,7 @@ // Statistics #define MAX_CONNECTION_QUEUE 5 #define INPUT_BUFFER_SIZE 256 +#define CLIENT_TIMEOUT 10 // Seconds #define HASH_TYPE SHA1 #define HASH_LENGTH 20 @@ -153,6 +154,18 @@ void Server_Start(void) return ; } + // Set a timeout on the user conneciton + { + struct timeval tv; + tv.tv_sec = CLIENT_TIMEOUT; + tv.tv_usec = 0; + if( setsockopt(client_socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) ) + { + perror("setsockopt"); + return ; + } + } + // Debug: Print the connection string if(giDebugLevel >= 2) { char ipstr[INET_ADDRSTRLEN]; @@ -225,6 +238,7 @@ void Server_HandleClient(int Socket, int bTrusted) * it is saved to the beginning of `inbuf` and `buf` is updated to * the end of it. */ + // TODO: Use select() instead (to give a timeout) while( (bytes = recv(Socket, buf, remspace, 0)) > 0 ) { char *eol, *start; @@ -1031,13 +1045,14 @@ void Server_Cmd_USERINFO(tClient *Client, char *Args) space = strchr(user, ' '); if(space) *space = '\0'; - if( giDebugLevel ) - Debug(Client, "User Info '%s'", user); + if( giDebugLevel ) Debug(Client, "User Info '%s'", user); // Get recipient uid = Bank_GetAcctByName(user); + + if( giDebugLevel >= 2 ) Debug(Client, "uid = %i", uid); if( uid == -1 ) { - sendf(Client->Socket, "404 Invalid user"); + sendf(Client->Socket, "404 Invalid user\n"); return ; } @@ -1160,9 +1175,10 @@ void Server_Cmd_USERFLAGS(tClient *Client, char *Args) void Debug(tClient *Client, const char *Format, ...) { va_list args; - printf("%010lli [%i] ", time(NULL), Client->ID); + //printf("%010i [%i] ", (int)time(NULL), Client->ID); + printf("[%i] ", Client->ID); va_start(args, Format); - vprintf(NULL, 0, Format, args); + vprintf(Format, args); va_end(args); printf("\n"); }