[project @ 2005-06-28 09:54:46 by unknown_lamer]
[clinton/bobotpp.git] / source / Socket.H
CommitLineData
cb21075d 1// Socket.H -*- C++ -*-
2// Copyright (c) 1997, 1998 Etienne BERNARD
3
4// This program is free software; you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation; either version 2 of the License, or
7// any later version.
8
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with this program; if not, write to the Free Software
39b022cb 16// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
cb21075d 17
18#ifndef SOCKET_H
19#define SOCKET_H
20
21
22#include "String.H"
23
24class Socket {
25 struct s_fd {
26 int fd; // the data
27 int n; // reference counter
28 s_fd() { n = 1; }
29 };
30 s_fd *fd;
31
32 int remotePort;
33 unsigned long remoteAddress;
34
35 int localPort;
36 unsigned long localAddress;
37
38 int begin, end;
39
cb21075d 40
41public:
42 Socket();
43 Socket(int, unsigned long, int);
44 Socket(const Socket &);
45
46 ~Socket();
47
48 int getRemotePort() const;
49 int getLocalPort() const;
50 int getFileDescriptor() const;
51
52 bool isConnected();
53
54 bool setRemoteHostname(String);
55 bool setRemoteIP(unsigned long);
56 bool setRemotePort(int);
57
58 bool setLocalHostname(String);
59 bool setLocalIP(unsigned long);
60 bool setLocalPort(int);
61
62 bool setNonBlocking(bool = true);
63
64 bool connect();
65 bool listen(int = 5);
66 Socket accept();
67 void close();
68
69 bool write(String, bool = false);
70 String readLine();
71 String readChar();
72 bool hasData();
73private:
74 Socket(Socket &);
75};
76
77#endif