From: John Hodge Date: Sat, 19 Feb 2011 06:12:27 +0000 (+0800) Subject: User timeouts, compile fixes X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=a76e13745dd39b23026ca38c256cc8f0b0d70116;p=tpg%2Fopendispense2.git User timeouts, compile fixes --- diff --git a/src/cokebank.h b/src/cokebank.h index ed4dff1..e5a4389 100644 --- a/src/cokebank.h +++ b/src/cokebank.h @@ -28,11 +28,24 @@ */ typedef struct sAcctIterator tAcctIterator; +#if 0 /** * \brief Iterator for a collection of items */ typedef struct sItemIterator tItemIterator; +/** + * \brief Item structure + */ +typedef struct +{ + char *Handler; + int ID; + int Price; + char Name[]; +} tItem; +#endif + /** * \brief Flag values for the \a Flags parameter to Bank_Iterator */ @@ -51,6 +64,19 @@ enum eBank_ItFlags BANK_ITFLAG_SORTMASK = 0x700, //!< Sort type mask BANK_ITFLAG_REVSORT = 0x800 //!< Sort descending instead }; +/** + * \brief Flag values for the \a Flags parameter to Items_Iterator + */ +enum eItems_ItFlags +{ + ITEMS_ITFLAG_SHOWDISABLED = 0x001, //!< Show disabled items + ITEMS_ITFLAG_SORT_NONE = 0x000, //!< No sorting (up to the implementation) + ITEMS_ITFLAG_SORT_NAME = 0x100, //!< Sort alphabetically ascending by name + ITEMS_ITFLAG_SORT_PRICE = 0x200, //!< Sort by price, ascending + ITEMS_ITFLAG_SORT_IDENT = 0x300, //!< Sort by Identifier (handler:id) + ITEMS_ITFLAG_SORTMASK = 0x700, //!< Sort type mask + ITEMS_ITFLAG_REVSORT = 0x800 //!< Sort descending instead +}; /** * \brief User flag values @@ -169,6 +195,29 @@ extern int Bank_GetAcctByCard(const char *CardID); */ extern int Bank_AddAcctCard(int AcctID, const char *CardID); +// === Item Manipulation === +#if 0 +extern tItem *Items_GetItem(char *Handler, int ID); +/** + * \brief Create an item iterator + * \return Pointer to an iterator across the selected data set + */ +extern tItemIterator *Items_Iterator(int Flags, char *Handler, int MaxPrice); + +/** + * \brief Get the current entry in the iterator and move to the next + * \param It Iterator returned by Items_Iterator + * \return Item ID, or -1 for end of list + */ +extern tItem *Items_IteratorNext(tItemIterator *It); + +/** + * \brief Free an allocated iterator + * \param It Iterator returned by Items_Iterator + */ +extern void Items_DelIterator(tItemIterator *It); +#endif + // --- // Server provided helper functions // --- diff --git a/src/server/handler_coke.c b/src/server/handler_coke.c index a8a1fee..5a6a86f 100644 --- a/src/server/handler_coke.c +++ b/src/server/handler_coke.c @@ -17,6 +17,7 @@ #include #include #include +#include #define READ_TIMEOUT 2 // 2 seconds for ReadChar #define TRACE_COKE 1 diff --git a/src/server/server.c b/src/server/server.c index 315b129..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;