MacSocket.h revision 1.1.1.1
1#pragma once 2 3 4#ifdef __cplusplus 5extern "C" { 6#endif 7 8 9 10enum 11{ 12 kMacSocket_TimeoutErr = -2 13}; 14 15 16// Since MacSocket does busy waiting, I do a callback while waiting 17 18typedef OSErr (*MacSocket_IdleWaitCallback)(void *); 19 20 21// Call this before anything else! 22 23OSErr MacSocket_Startup(void); 24 25 26// Call this to cleanup before quitting 27 28OSErr MacSocket_Shutdown(void); 29 30 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 37OSErr 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 43OSErr MacSocket_connect(const int inSocketNum,char *inTargetAddressAndPort); 44 45 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 48 49OSErr MacSocket_listen(const int inSocketNum,const int inPortNum); 50 51 52// Call this to close a socket 53 54OSErr MacSocket_close(const int inSocketNum); 55 56 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 59 60int MacSocket_recv(const int inSocketNum,void *outBuff,int outBuffLength,const Boolean inBlock); 61 62 63// Call this to send data on a socket 64 65int 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 70 71Boolean MacSocket_RemoteEndIsClosing(const int inSocketNum); 72 73 74// Call this to see if the listen has completed after a call to MacSocket_listen() 75 76Boolean MacSocket_ListenCompleted(const int inSocketNum); 77 78 79// These really aren't very useful anymore 80 81Boolean MacSocket_LocalEndIsOpen(const int inSocketNum); 82Boolean MacSocket_RemoteEndIsOpen(const int inSocketNum); 83 84 85// You may wish to change the userRefPtr for a socket callback-- use this to do it 86 87void MacSocket_SetUserRefPtr(const int inSocketNum,void *inNewRefPtr); 88 89 90// Call these to get the socket's IP:port descriptor 91 92void MacSocket_GetLocalIPAndPort(const int inSocketNum,char *outIPAndPort,const int inIPAndPortLength); 93void MacSocket_GetRemoteIPAndPort(const int inSocketNum,char *outIPAndPort,const int inIPAndPortLength); 94 95 96// Call this to get error info from a socket 97 98void MacSocket_GetSocketErrorInfo(const int inSocketNum,int *outSocketErrCode,char *outSocketErrString,const int inSocketErrStringMaxLength); 99 100 101#ifdef __cplusplus 102} 103#endif 104