12 kMacSocket_TimeoutErr = -2
16 // Since MacSocket does busy waiting, I do a callback while waiting
18 typedef OSErr (*MacSocket_IdleWaitCallback)(void *);
21 // Call this before anything else!
23 OSErr MacSocket_Startup(void);
26 // Call this to cleanup before quitting
28 OSErr MacSocket_Shutdown(void);
31 // Call this to allocate a "socket" (reference number is returned in outSocketNum)
32 // Note that inDoThreadSwitching is pretty much irrelevant right now, since I ignore it
33 // The inTimeoutTicks parameter is applied during reads/writes of data
34 // The inIdleWaitCallback parameter specifies a callback which is called during busy-waiting periods
35 // The inUserRefPtr parameter is passed back to the idle-wait callback
37 OSErr MacSocket_socket(int *outSocketNum,const Boolean inDoThreadSwitching,const long inTimeoutTicks,MacSocket_IdleWaitCallback inIdleWaitCallback,void *inUserRefPtr);
40 // Call this to connect to an IP/DNS address
41 // Note that inTargetAddressAndPort is in "IP:port" format-- e.g. 10.1.1.1:123
43 OSErr MacSocket_connect(const int inSocketNum,char *inTargetAddressAndPort);
46 // Call this to listen on a port
47 // Since this a low-performance implementation, I allow a maximum of 1 (one!) incoming request when I listen
49 OSErr MacSocket_listen(const int inSocketNum,const int inPortNum);
52 // Call this to close a socket
54 OSErr MacSocket_close(const int inSocketNum);
57 // Call this to receive data on a socket
58 // Most parameters' purpose are obvious-- except maybe "inBlock" which controls whether I wait for data or return immediately
60 int MacSocket_recv(const int inSocketNum,void *outBuff,int outBuffLength,const Boolean inBlock);
63 // Call this to send data on a socket
65 int MacSocket_send(const int inSocketNum,const void *inBuff,int inBuffLength);
68 // If zero bytes were read in a call to MacSocket_recv(), it may be that the remote end has done a half-close
69 // This function will let you check whether that's true or not
71 Boolean MacSocket_RemoteEndIsClosing(const int inSocketNum);
74 // Call this to see if the listen has completed after a call to MacSocket_listen()
76 Boolean MacSocket_ListenCompleted(const int inSocketNum);
79 // These really aren't very useful anymore
81 Boolean MacSocket_LocalEndIsOpen(const int inSocketNum);
82 Boolean MacSocket_RemoteEndIsOpen(const int inSocketNum);
85 // You may wish to change the userRefPtr for a socket callback-- use this to do it
87 void MacSocket_SetUserRefPtr(const int inSocketNum,void *inNewRefPtr);
90 // Call these to get the socket's IP:port descriptor
92 void MacSocket_GetLocalIPAndPort(const int inSocketNum,char *outIPAndPort,const int inIPAndPortLength);
93 void MacSocket_GetRemoteIPAndPort(const int inSocketNum,char *outIPAndPort,const int inIPAndPortLength);
96 // Call this to get error info from a socket
98 void MacSocket_GetSocketErrorInfo(const int inSocketNum,int *outSocketErrCode,char *outSocketErrString,const int inSocketErrStringMaxLength);