1#ifndef __DCL_SOCKET_H__
2#define __DCL_SOCKET_H__ 20030501
4#ifndef __DCL_CONFIG_H__
10 #error "Required winsock2.h, See dcl/_windows.h"
14 #pragma comment(lib, "ws2_32.lib")
17 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
23#ifndef __DCL_POLL_ABLE_H__
30 typedef int socklen_t;
49 void open(
const String& _addr, uint16_t _port)
55 virtual size_t read(
void* _buf,
size_t _n)
58 virtual size_t write(
const void* _buf,
size_t _n)
66 struct sockaddr_in sa_in;
67 struct sockaddr_in6 sa_in6;
69 struct sockaddr_un sa_un;
81 Addr(
const char* _addr, uint16_t _port)
84 Addr(
const String& _addr, uint16_t _port)
91 Addr(
const char* _path)
94 Addr(
const String& _path)
110 void bind(
const Addr& _my_addr,
111 int _type = SOCK_STREAM,
int _protocol = 0,
bool _reuse =
true
114 void accept(Socket&
_r)
117 void connect(
const Addr& _serv_addr)
120 socklen_t getsockname(Addr& _addr)
123 socklen_t getpeername(Addr& _addr)
130 Socket(
const String& _addr, uint16_t _port)
139 void create(
int _domain = AF_INET,
int _type = SOCK_STREAM,
int _protocol = 0)
145 void bind(
const struct sockaddr* _my_addr, socklen_t _addrlen)
148 void listen(
unsigned _backlog = 5)
151 void accept(Socket&
r,
struct sockaddr* _addr, socklen_t* _addrlen)
154 virtual void connect(
const sockaddr* _serv_addr, socklen_t _addrlen)
160 virtual size_t send(
const void* _buf,
size_t _n,
int _flags = 0)
166 virtual size_t recv(
void* _buf,
size_t _n,
int _flags = 0)
180 WSAEVENT __waitEvent;
#define DECLARE_CLASSINFO(class_name)
__DCL_BEGIN_NAMESPACE typedef PollThread SocketPollThread
void open(const String &_path, int _oflags=READONLY, int _mode=0666) __DCL_THROWS1(IOException *)
virtual size_t read(void *_buf, size_t _n) __DCL_THROWS1(IOException *)
virtual String toString() const
virtual size_t write(const void *_buf, size_t _n) __DCL_THROWS1(IOException *)
virtual size_t available() const __DCL_THROWS1(IOException *)
virtual bool onEvent(short _revents, PollThread *_pPollThread) __DCL_THROWS1(IOException *)