PageRenderTime 28ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/nil/src/common/net/tcp_server.h

#
C Header | 77 lines | 29 code | 5 blank | 43 comment | 0 complexity | 1adbd5c6e0621ddbdbcd88a389b3cea3 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-3.0
  1. /***************************************************************************
  2. tcp_server.h - Header TCP handling for server
  3. --------------------------------------------------------------------------
  4. begin : 1999-11-13
  5. by : Flemming Frandsen
  6. email : dion@swamp.dk
  7. last changed : 2004-01-25
  8. by : Christoph Brill
  9. email : egore@gmx.de
  10. last changed : 2005-01-03
  11. by : Christoph Brill
  12. email : egore@gmx.de
  13. changedescription : minor cleanup
  14. copyright : (C) 1999 by Flemming Frandsen
  15. email : dion@swamp.dk
  16. ***************************************************************************/
  17. #ifndef TCP_SERVER_H
  18. #define TCP_SERVER_H
  19. #include "common/net/tcp_server_connection.h"
  20. #include "common/systemheaders.h"
  21. #include "server/serverworld.h"
  22. #include "common/serializer/update_queue.h"
  23. #define MAX_CONNECTIONS 128
  24. //! @author Flemming Frandsen
  25. //! @brief This class is used for the server side of TCP/IP communication
  26. class Tcp_server {
  27. public:
  28. /*! Opens a port and begins to listen to it (initializes the server)
  29. @param port the port we are listening to
  30. @param multithreaded_ Used to determine if we run multithreaded
  31. @return Returns the different errors or 0 if sucessful */
  32. int bind_and_listen(int port, bool multithreaded_);
  33. //! ???
  34. void poll();
  35. //! ???
  36. Tcp_server();
  37. //! ???
  38. ~Tcp_server();
  39. //! ???
  40. bool is_multithreaded();
  41. /*! This should be called from time to time to find out what the oldest relevant update is and then
  42. have the updates_queue recycle all serializers older than this. */
  43. void recycle_serializers();
  44. //! set timeouts etc.
  45. void set_fudge(int normal_backlog, int abnormal_backlog, int max_wait_time);
  46. //! returns no. of connections that are still in use
  47. int get_connections_inuse();
  48. //! Connections to the clients
  49. Tcp_server_connection *connections[MAX_CONNECTIONS];
  50. //! No. of connections in use
  51. int connections_inuse;
  52. //! The server world object
  53. Serverworld *serverworld;
  54. //! Queued updates to send to clients
  55. Update_queue update_queue;
  56. protected:
  57. //! Everything is ok as long as you don't get further behind than this
  58. int net_normal_backlog;
  59. //! Kick clients that are this far behind.
  60. int net_abnormal_backlog;
  61. //! the number of deca ms we wait for all clients to catch up.
  62. int net_max_wait_time;
  63. //! Socket for the server to listen for client connections
  64. int server_socket;
  65. //! Is the server multithreaded?
  66. bool multithreaded;
  67. };
  68. #endif