Debian Codegraph @

src/socket.h

raw
1 // Copyright © 2002-2004 Rob Kaper <[email protected]>.
2 // 2010-2015 Sylvain Rochet <[email protected]>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // version 2 as published by the Free Software Foundation.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; see the file COPYING. If not, see
15 // <http://www.gnu.org/licenses/>.
16
17 #ifndef NETWORK_SOCKET_H
18 #define NETWORK_SOCKET_H
19
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <netdb.h>
23
24 #include <string>
25
26 /*
27 * Class to handle incoming sockets. Can/will be used to store fd
28 * information, etc etc.
29 */
30
31 class Socket
32 {
33 public:
34 enum Status { Connect, Ok, Close };
35 enum Type { Player, Metaserver };
36
37 Socket(int fd);
38 void setStatus(Status status) { m_status = status; }
39 Status status() { return m_status; }
40 void setType(Type type) { m_type = type; }
41 Type type() { return m_type; }
42
43 void ioWrite(const std::string data);
44 void sendMore();
45 bool hasReadLine();
46 const std::string readLine();
47 void fillBuffer(const std::string data);
48 bool sendBufNotEmpty() { return (m_sendBuf.size() > 0); };
49
50 void setFd(int _fd) { m_fd = _fd; }
51 int fd() const { return m_fd; }
52 void setIpAddr(const std::string ipAddr) { m_ipAddr = ipAddr; }
53 std::string ipAddr() const { return m_ipAddr; }
54 void setAddrinfoNext(struct addrinfo *next) { m_addrinfoNext = next; }
55 struct addrinfo *addrinfoNext() { return m_addrinfoNext; }
56
57 private:
58 Status m_status;
59 Type m_type;
60 int m_fd;
61 std::string m_ipAddr, m_recvBuf, m_sendBuf;
62 struct addrinfo *m_addrinfoNext;
63 };
64
65 #endif // NETWORK_SOCKET_H