|
5 | 5 | extern "C" { |
6 | 6 | #endif |
7 | 7 |
|
8 | | - |
9 | | - |
10 | | -enum |
11 | | -{ |
12 | | - kMacSocket_TimeoutErr = -2 |
| 8 | +enum { |
| 9 | + kMacSocket_TimeoutErr = -2 |
13 | 10 | }; |
14 | 11 |
|
| 12 | +// Since MacSocket does busy waiting, I do a callback while waiting |
15 | 13 |
|
16 | | -// Since MacSocket does busy waiting, I do a callback while waiting |
17 | | - |
18 | | -typedef OSErr (*MacSocket_IdleWaitCallback)(void *); |
| 14 | +typedef OSErr(*MacSocket_IdleWaitCallback) (void *); |
19 | 15 |
|
20 | | - |
21 | | -// Call this before anything else! |
| 16 | +// Call this before anything else! |
22 | 17 |
|
23 | 18 | OSErr MacSocket_Startup(void); |
24 | 19 |
|
25 | | - |
26 | | -// Call this to cleanup before quitting |
| 20 | +// Call this to cleanup before quitting |
27 | 21 |
|
28 | 22 | OSErr MacSocket_Shutdown(void); |
29 | 23 |
|
| 24 | +// Call this to allocate a "socket" (reference number is returned in |
| 25 | +// outSocketNum) |
| 26 | +// Note that inDoThreadSwitching is pretty much irrelevant right now, since I |
| 27 | +// ignore it |
| 28 | +// The inTimeoutTicks parameter is applied during reads/writes of data |
| 29 | +// The inIdleWaitCallback parameter specifies a callback which is called |
| 30 | +// during busy-waiting periods |
| 31 | +// The inUserRefPtr parameter is passed back to the idle-wait callback |
30 | 32 |
|
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 |
36 | | - |
37 | | -OSErr MacSocket_socket(int *outSocketNum,const Boolean inDoThreadSwitching,const long inTimeoutTicks,MacSocket_IdleWaitCallback inIdleWaitCallback,void *inUserRefPtr); |
38 | | - |
39 | | - |
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 |
42 | | - |
43 | | -OSErr MacSocket_connect(const int inSocketNum,char *inTargetAddressAndPort); |
| 33 | +OSErr MacSocket_socket(int *outSocketNum, const Boolean inDoThreadSwitching, |
| 34 | + const long inTimeoutTicks, |
| 35 | + MacSocket_IdleWaitCallback inIdleWaitCallback, |
| 36 | + void *inUserRefPtr); |
44 | 37 |
|
| 38 | +// Call this to connect to an IP/DNS address |
| 39 | +// Note that inTargetAddressAndPort is in "IP:port" format-- e.g. |
| 40 | +// 10.1.1.1:123 |
45 | 41 |
|
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 |
| 42 | +OSErr MacSocket_connect(const int inSocketNum, char *inTargetAddressAndPort); |
48 | 43 |
|
49 | | -OSErr MacSocket_listen(const int inSocketNum,const int inPortNum); |
| 44 | +// Call this to listen on a port |
| 45 | +// Since this a low-performance implementation, I allow a maximum of 1 (one!) |
| 46 | +// incoming request when I listen |
50 | 47 |
|
| 48 | +OSErr MacSocket_listen(const int inSocketNum, const int inPortNum); |
51 | 49 |
|
52 | | -// Call this to close a socket |
| 50 | +// Call this to close a socket |
53 | 51 |
|
54 | 52 | OSErr MacSocket_close(const int inSocketNum); |
55 | 53 |
|
| 54 | +// Call this to receive data on a socket |
| 55 | +// Most parameters' purpose are obvious-- except maybe "inBlock" which |
| 56 | +// controls whether I wait for data or return immediately |
56 | 57 |
|
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 |
| 58 | +int MacSocket_recv(const int inSocketNum, void *outBuff, int outBuffLength, |
| 59 | + const Boolean inBlock); |
59 | 60 |
|
60 | | -int MacSocket_recv(const int inSocketNum,void *outBuff,int outBuffLength,const Boolean inBlock); |
| 61 | +// Call this to send data on a socket |
61 | 62 |
|
| 63 | +int MacSocket_send(const int inSocketNum, const void *inBuff, |
| 64 | + int inBuffLength); |
62 | 65 |
|
63 | | -// Call this to send data on a socket |
64 | | - |
65 | | -int MacSocket_send(const int inSocketNum,const void *inBuff,int inBuffLength); |
66 | | - |
67 | | - |
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 |
| 66 | +// If zero bytes were read in a call to MacSocket_recv(), it may be that the |
| 67 | +// remote end has done a half-close |
| 68 | +// This function will let you check whether that's true or not |
70 | 69 |
|
71 | 70 | Boolean MacSocket_RemoteEndIsClosing(const int inSocketNum); |
72 | 71 |
|
73 | | - |
74 | | -// Call this to see if the listen has completed after a call to MacSocket_listen() |
| 72 | +// Call this to see if the listen has completed after a call to |
| 73 | +// MacSocket_listen() |
75 | 74 |
|
76 | 75 | Boolean MacSocket_ListenCompleted(const int inSocketNum); |
77 | 76 |
|
78 | | - |
79 | | -// These really aren't very useful anymore |
| 77 | +// These really aren't very useful anymore |
80 | 78 |
|
81 | 79 | Boolean MacSocket_LocalEndIsOpen(const int inSocketNum); |
82 | 80 | Boolean MacSocket_RemoteEndIsOpen(const int inSocketNum); |
83 | 81 |
|
| 82 | +// You may wish to change the userRefPtr for a socket callback-- use this to |
| 83 | +// do it |
84 | 84 |
|
85 | | -// You may wish to change the userRefPtr for a socket callback-- use this to do it |
86 | | - |
87 | | -void MacSocket_SetUserRefPtr(const int inSocketNum,void *inNewRefPtr); |
88 | | - |
89 | | - |
90 | | -// Call these to get the socket's IP:port descriptor |
| 85 | +void MacSocket_SetUserRefPtr(const int inSocketNum, void *inNewRefPtr); |
91 | 86 |
|
92 | | -void MacSocket_GetLocalIPAndPort(const int inSocketNum,char *outIPAndPort,const int inIPAndPortLength); |
93 | | -void MacSocket_GetRemoteIPAndPort(const int inSocketNum,char *outIPAndPort,const int inIPAndPortLength); |
| 87 | +// Call these to get the socket's IP:port descriptor |
94 | 88 |
|
| 89 | +void MacSocket_GetLocalIPAndPort(const int inSocketNum, char *outIPAndPort, |
| 90 | + const int inIPAndPortLength); |
| 91 | +void MacSocket_GetRemoteIPAndPort(const int inSocketNum, char *outIPAndPort, |
| 92 | + const int inIPAndPortLength); |
95 | 93 |
|
96 | | -// Call this to get error info from a socket |
| 94 | +// Call this to get error info from a socket |
97 | 95 |
|
98 | | -void MacSocket_GetSocketErrorInfo(const int inSocketNum,int *outSocketErrCode,char *outSocketErrString,const int inSocketErrStringMaxLength); |
| 96 | +void MacSocket_GetSocketErrorInfo(const int inSocketNum, |
| 97 | + int *outSocketErrCode, |
| 98 | + char *outSocketErrString, |
| 99 | + const int inSocketErrStringMaxLength); |
99 | 100 |
|
100 | 101 |
|
101 | 102 | #ifdef __cplusplus |
|
0 commit comments