Addons updated to new doc format
[io.git] / addons / Socket / source / Socket.h
blobbaffeee58e72607bcd3c767bb606b83fe68041f0
1 /*
2 //metadoc copyright Steve Dekorte 2002
3 */
4 //metadoc license BSD revised
5 /*metadoc description
6 See the release notes for a list of folks that helped with this code.")
7 */
9 #ifndef PORTABLESOCKET_DEFINED
10 #define PORTABLESOCKET_DEFINED 1
12 #include <sys/types.h>
14 #ifndef WIN32
15 #include <sys/uio.h>
16 #include <sys/types.h>
17 #include <unistd.h>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
21 #include <netdb.h>
22 #include <signal.h>
23 #include <sys/ioctl.h>
24 #include <sys/time.h>
25 #else
26 #include <winsock2.h>
28 // for dog4
29 #ifndef IO_WINSOCK_COMPAT
30 #define IO_WINSOCK_COMPAT
31 typedef size_t socklen_t;
32 typedef SSIZE_T ssize_t;
33 #endif
35 #endif
37 #include <stdlib.h>
38 #include <string.h>
39 #include <ctype.h>
40 #include <stdio.h>
41 #include <errno.h>
42 #include <fcntl.h>
44 #ifdef sun
45 #include <sys/file.h> /* for FASYNC */
46 #endif
48 #ifndef SOMAXCONN
49 #define SOMAXCONN 128
50 #endif
52 #ifdef WIN32
53 typedef SOCKET SOCKET_DESCRIPTOR;
54 #define SocketResetErrorStatus() WSASetLastError(0)
55 #define SocketErrorStatus() WSAGetLastError()
56 #else
57 typedef int SOCKET_DESCRIPTOR;
58 #define SocketResetErrorStatus() errno = 0
59 #define SocketErrorStatus() errno
60 #endif
62 #include "IPAddress.h"
63 #include "UArray.h"
65 typedef struct
67 SOCKET_DESCRIPTOR fd;
68 } Socket;
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);
111 #endif