[project @ 2002-07-07 02:33:51 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
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
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
40 char buf[1024];
41
42public:
43 Socket();
44 Socket(int, unsigned long, int);
45 Socket(const Socket &);
46
47 ~Socket();
48
49 int getRemotePort() const;
50 int getLocalPort() const;
51 int getFileDescriptor() const;
52
53 bool isConnected();
54
55 bool setRemoteHostname(String);
56 bool setRemoteIP(unsigned long);
57 bool setRemotePort(int);
58
59 bool setLocalHostname(String);
60 bool setLocalIP(unsigned long);
61 bool setLocalPort(int);
62
63 bool setNonBlocking(bool = true);
64
65 bool connect();
66 bool listen(int = 5);
67 Socket accept();
68 void close();
69
70 bool write(String, bool = false);
71 String readLine();
72 String readChar();
73 bool hasData();
74private:
75 Socket(Socket &);
76};
77
78#endif