All Classes Namespaces Functions Variables Enumerations Enumerator Pages
SocketHandler.h
1 /*
2  Copyright (c) 2014 by Elvis Angelaccio
3 
4  Permission is hereby granted, free of charge, to any person obtaining a copy
5  of this software and associated documentation files (the "Software"), to deal
6  in the Software without restriction, including without limitation the rights
7  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  copies of the Software, and to permit persons to whom the Software is
9  furnished to do so, subject to the following conditions:
10 
11  The above copyright notice and this permission notice shall be included in
12  all copies or substantial portions of the Software.
13 
14  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  THE SOFTWARE.
21 */
22 
23 #ifndef CLIENT_SERVICE_H
24 #define CLIENT_SERVICE_H
25 
26 #include "net.h"
27 
28 namespace net
29 {
30 
38  {
39 
40  public:
41 
42  SocketHandler(Port port);
43  ~SocketHandler();
44 
45  static const int GENERIC_SOCKET_ERROR = -1;
46  static const int DEFAULT_SOCKET_DESCRIPTOR = -1;
47  static const Port DEFAULT_INVALID_PORT = -1;
48 
49  protected:
50 
51  static const int MESSAGE_BUFFER_SIZE = 8192;
52  static const char END_OF_MESSAGE = 3;
53  Port serverPort;
60  int getLastErrorCode();
61 
67  bool closeSocket(int descriptor);
68 
69  private:
70 
72  void winsockStartup(); // TODO: #ifdef WIN here?
73  };
74 }
75 
76 
77 
78 
79 #endif
80 
bool closeSocket(int descriptor)
Definition: SocketHandler.cpp:80
SocketState
Definition: net.h:44
Base Class with basic convenience support for its derived classes.
Definition: SocketHandler.h:37
Definition: client_protocol.cpp:725
SocketState currentState
Definition: SocketHandler.h:54
int getLastErrorCode()
Definition: SocketHandler.cpp:67