7 #ifndef __platform_Socket_h__ 8 #define __platform_Socket_h__ 14 typedef int SockHandle;
22 memset(&m_sockaddr, 0,
sizeof(m_sockaddr));
23 m_sockaddr.sin_family = AF_INET;
24 setAddress(INADDR_ANY);
28 struct sockaddr *
ptr(
void)
30 return (
struct sockaddr *)&m_sockaddr;
35 return sizeof(m_sockaddr);
40 m_sockaddr.sin_port = htons((
short)port);
45 m_sockaddr.sin_addr.s_addr = htonl(address);
49 void setAddress(
const String &host);
54 return (
long)ntohs(m_sockaddr.sin_port);
57 static U32 getIp4Address(
const String &host);
60 struct sockaddr_in m_sockaddr;
105 virtual void openStream(Transport transport=e_tcp,
108 virtual SockHandle socket(
int domain,
int type,
int protocol);
111 virtual void bind(
SockAddr &sockaddr);
113 virtual void listen(
int backlog);
117 virtual void connect(
SockAddr &sockaddr);
119 virtual IWORD read(
const void *pBuffer, IWORD count,
120 ReadMode readMode=e_readNormal);
122 virtual IWORD write(
const void *pBuffer, IWORD count);
125 virtual void setPoison(
Poison *pPoison);
129 virtual void wait(
void);
132 virtual void close(
void);
135 virtual bool isOpen(
void);
140 virtual U32 id(
void);
144 static void startup(
void);
146 static void shutdown(
void);
147 SockHandle sockHandle()
const {
return m_sock_handle;}
150 Transport transportType()
const {
return m_transportType;}
151 SockAddr sockAddrOwn()
const {
return m_udpSockAddrOwn;}
154 IWORD udpRead(
const void *pBuffer, IWORD count,
156 IWORD udpWrite(
const void *pBuffer, IWORD count);
158 SockHandle m_sock_handle;
164 Transport m_transportType;
167 #if FE_OS==FE_WIN32 || FE_OS==FE_WIN64 168 static bool m_wsaStarted;
Object level locking for thread safety.
Definition: Safe.h:216
int size(void)
Return size of address.
Definition: Socket.h:33
Heap-based support for classes participating in fe::ptr <>
Definition: Counted.h:35
kernel
Definition: namespace.dox:3
A socket wrapper.
Definition: Socket.h:81
BSD socket address wrapper.
Definition: Socket.h:17
struct sockaddr * ptr(void)
Access pointer to underlying (struct sockaddr *)
Definition: Socket.h:28
Automatically reference-counted string container.
Definition: String.h:128
void setPort(FE_UWORD port)
Set the port.
Definition: Socket.h:38
Death pill for threads.
Definition: Poison.h:15
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
void setAddress(const U32 address)
Set the address.
Definition: Socket.h:43