1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tools/daemon/smud_connections.h Mon Jun 30 02:34:21 2008 +0000
1.3 @@ -0,0 +1,109 @@
1.4 +#ifndef _INCLUDE_SMUD_CONNECTION_H_
1.5 +#define _INCLUDE_SMUD_CONNECTION_H_
1.6 +
1.7 +#include "smud.h"
1.8 +#include <list>
1.9 +#include "poll.h"
1.10 +
1.11 +enum ConnectionState
1.12 +{
1.13 + ConnectionState_ReadQueryHeader,
1.14 + ConnectionState_ReadQueryData,
1.15 + ConnectionState_ReplyQuery,
1.16 + ConnectionState_SendingFiles,
1.17 + ConnectionState_SendUnknownList,
1.18 + ConnectionState_Complete,
1.19 +};
1.20 +
1.21 +enum QueryResult
1.22 +{
1.23 + QueryResult_Continue,
1.24 + QueryResult_Complete,
1.25 +};
1.26 +
1.27 +enum MD5Status
1.28 +{
1.29 + MD5Status_Unknown,
1.30 + MD5Status_Current,
1.31 + MD5Status_NeedsUpdate,
1.32 +};
1.33 +
1.34 +enum UpdateStatus
1.35 +{
1.36 + Update_Unknown = 0, /* Version wasn't recognised or version querying is unsupported */
1.37 + Update_Current = 1, /* Server is running latest version */
1.38 + Update_NewBuild = 2, /* Server is on a svn release and a newer version is available */
1.39 + Update_MinorAvailable = 3, /* Server is on a release and a minor release has superceeded it */
1.40 + Update_MajorAvailable = 4, /* Server is on a release and a major release has superceeded it */
1.41 + Update_CriticalAvailable = 5, /* A critical update has been released (security fixes etc) */
1.42 +};
1.43 +
1.44 +struct smud_connection
1.45 +{
1.46 + smud_connection(int fd)
1.47 + {
1.48 + shouldSend = NULL;
1.49 + fileLocation = NULL;
1.50 + headerSent = NULL;
1.51 + sentSums = 0;
1.52 + sendCount = 0;
1.53 + currentFile = 0;
1.54 + unknownCount = 0;
1.55 + pollData.events = POLLIN;
1.56 + start = time(NULL);
1.57 + state = ConnectionState_ReadQueryHeader;
1.58 + this->fd = fd;
1.59 + pollData.fd = fd;
1.60 + }
1.61 +
1.62 + ~smud_connection()
1.63 + {
1.64 + if (shouldSend != NULL)
1.65 + delete [] shouldSend;
1.66 + if (fileLocation != NULL)
1.67 + delete [] fileLocation;
1.68 + if (headerSent != NULL)
1.69 + delete [] headerSent;
1.70 + }
1.71 +
1.72 + int fd; /** Socket file descriptor */
1.73 + time_t start; /** The time this connection was received (for timeouts) */
1.74 + ConnectionState state; /** How far through processing the connection we are */
1.75 + uint8_t sentSums; /** Number of MD5 Sums sent from the client */
1.76 + MD5Status *shouldSend; /** Arrays of statuses for each sum */
1.77 + int *fileLocation; /** Array of indexes into the global file list for each sum (only valid if shouldSend[i] == MD5Status_NeedsUpdate) */
1.78 + bool *headerSent; /** Has the header been sent yet for each sum? Header == file index and size */
1.79 + int sendCount; /** Number of files that need to be sent */
1.80 + int unknownCount; /** Number of files that were unknown */
1.81 + int currentFile; /** Current file being sent (index into the above 3 arrays) */
1.82 + pollfd pollData; /** Data to be passed into poll() */
1.83 +};
1.84 +
1.85 +
1.86 +
1.87 +class ConnectionPool
1.88 +{
1.89 +public:
1.90 + ConnectionPool();
1.91 + ~ConnectionPool();
1.92 +public:
1.93 + void AddConnection(int fd);
1.94 + void Process(bool *terminate);
1.95 +private:
1.96 + QueryResult ProcessConnection(smud_connection *con);
1.97 + void ReadQueryHeader(smud_connection *con);
1.98 + void ReadQueryContent(smud_connection *con);
1.99 + void ReplyQuery(smud_connection *con);
1.100 + void SendFile(smud_connection *con);
1.101 + void SendUnknownList(smud_connection *con);
1.102 +
1.103 + MD5Status GetMD5UpdateStatus(const char *md5, smud_connection *con, int fileNum);
1.104 +private:
1.105 + std::list<smud_connection *> m_Links;
1.106 + std::list<smud_connection *> m_AddQueue;
1.107 + pthread_mutex_t m_AddLock;
1.108 + time_t m_timeOut;
1.109 +};
1.110 +
1.111 +#endif //_INCLUDE_SMUD_CONNECTION_H_
1.112 +