xref: /haiku/src/add-ons/print/transports/shared/Socket.h (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
1 // Sun, 18 Jun 2000
2 // Y.Takagi
3 
4 #ifndef __Socket_H
5 #define __Socket_H
6 
7 #ifdef WIN32
8 #include <istream>
9 #include <ostream>
10 #else
11 #include <istream.h>
12 #include <ostream.h>
13 #endif	// WIN32
14 
15 #include <string>
16 
17 #if (!__MWERKS__ || defined(WIN32))
18 using namespace std;
19 #else
20 #define std
21 #endif
22 
23 class Socket {
24 public:
25 	Socket(const char *host, int port);
26 	Socket(const char *host, int port, int localPort);
27 	~Socket();
28 
29 	bool operator !() const;
30 	bool good() const;
31 	bool fail() const;
32 
33 	void close();
34 	int read(char *buffer, int size, int flags = 0);
35 	int write(const char *buffer, int size, int flags = 0);
36 
37 	istream &getInputStream();
38 	ostream &getOutputStream();
39 
40 	int getPort() const;
41 	const char *getLastError() const;
42 
43 private:
44 	Socket(const Socket &);
45 	Socket &operator = (const Socket &);
46 	void open();
47 
48 	string  __host;
49 	int     __port;
50 	int     __localPort;
51 	int     __sock;
52 	istream *__is;
53 	ostream *__os;
54 	bool    __error;
55 	char    __error_msg[256];
56 };
57 
58 inline int Socket::getPort() const
59 {
60 	return __port;
61 }
62 
63 inline const char *Socket::getLastError() const
64 {
65 	return __error_msg;
66 }
67 
68 #endif // __Socket_H
69