2 //metadoc copyright Steve Dekorte 2002
4 //metadoc license BSD revised
6 See the release notes for a list of folks that helped with this code.")
9 #ifndef PORTABLESOCKET_DEFINED
10 #define PORTABLESOCKET_DEFINED 1
12 #include <sys/types.h>
16 #include <sys/types.h>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
23 #include <sys/ioctl.h>
29 #ifndef IO_WINSOCK_COMPAT
30 #define IO_WINSOCK_COMPAT
31 typedef size_t socklen_t
;
32 typedef SSIZE_T ssize_t
;
45 #include <sys/file.h> /* for FASYNC */
53 typedef SOCKET SOCKET_DESCRIPTOR
;
54 #define SocketResetErrorStatus() WSASetLastError(0)
55 #define SocketErrorStatus() WSAGetLastError()
57 typedef int SOCKET_DESCRIPTOR
;
58 #define SocketResetErrorStatus() errno = 0
59 #define SocketErrorStatus() errno
62 #include "IPAddress.h"
70 void Socket_GlobalInit(void);
71 void Socket_GlobalCleanup(void);
72 long Socket_SetDescriptorLimitToMax(void);
74 Socket
*Socket_new(void);
75 void Socket_free(Socket
*self
);
77 //void Socket_setError_(Socket *self, const char *e);
78 //const char *Socket_error(Socket *self);
80 void Socket_setDescriptor_(Socket
*self
, SOCKET_DESCRIPTOR fd
);
81 SOCKET_DESCRIPTOR
Socket_descriptor(Socket
*self
);;
83 int Socket_isStream(Socket
*self
);
84 int Socket_isOpen(Socket
*self
);
85 int RawDescriptor_isValid(int fd
);
86 int Socket_isValid(Socket
*self
);
88 int Socket_makeReusable(Socket
*self
);
89 int Socket_makeAsync(Socket
*self
);
91 int Socket_streamOpen(Socket
*self
);
92 int Socket_udpOpen(Socket
*self
);
94 int Socket_connectTo(Socket
*self
, IPAddress
*address
);
95 int Socket_connectToFailed(void);
96 int Socket_close(Socket
*self
);
97 int Socket_closeFailed(void);
99 int Socket_bind(Socket
*self
, IPAddress
*address
);
100 int Socket_listen(Socket
*self
);
101 int Socket_asyncFailed(void);
102 Socket
*Socket_accept(Socket
*self
, IPAddress
*address
);
104 ssize_t
Socket_streamRead(Socket
*self
, UArray
*buffer
, size_t readSize
);
105 ssize_t
Socket_streamWrite(Socket
*self
, UArray
*buffer
, size_t start
, size_t writeSize
);
107 ssize_t
Socket_udpRead(Socket
*self
, IPAddress
*address
, UArray
*buffer
, size_t readSize
);
108 ssize_t
Socket_udpWrite(Socket
*self
, IPAddress
*address
, UArray
*buffer
, size_t start
, size_t writeSize
);
110 char *Socket_errorDescription(void);