00001 #ifndef __NS2NET_H 00002 #define __NS2NET_H 00003 00011 struct NSNet; 00012 struct NSNetConnectionController; 00013 00014 typedef void (*NSNetFunc)(void *udata); 00015 typedef void (*NSNetReadFunc)(void *udata, const char *bytes, int len); 00016 typedef void (*NSNetSuccessFunc)(void *udata, struct NSNetConnectionController *nscc); 00017 00018 struct NSNetConnectionHandler { 00019 NSNetSuccessFunc success; 00020 NSNetFunc refused; 00021 NSNetFunc timedOut; 00022 NSNetFunc unknownHost; 00023 }; 00024 00025 struct NSNetBindHandler { 00026 NSNetSuccessFunc success; 00027 NSNetFunc error; 00028 }; 00029 00030 struct NSNetConnectionReadHandler { 00031 NSNetFunc closed; 00032 NSNetReadFunc bytesRead; 00033 }; 00034 00040 struct NSNet *newNSNet(void); 00046 void waitForNetEvent(struct NSNet *ns, int timeout); 00047 00052 void closeNSNet(struct NSNet *ns); 00074 int attemptBind(struct NSNet *ns, const struct NSNetBindHandler *nsb, 00075 int isLocalOnly, unsigned short portNum, void *udata); 00095 int attemptConnect(struct NSNet *ns, const struct NSNetConnectionHandler *nsc, 00096 const char *destaddr, unsigned short destPort, void *udata); 00112 int attachConnectionReadHandler(struct NSNetConnectionController *nscc, 00113 const struct NSNetConnectionReadHandler *nscch, void *udata); 00125 int writeNSBytes(struct NSNetConnectionController *nscc, void *buf, int len); 00126 00134 int closeConnection(struct NSNetConnectionController *nscc); 00135 00136 #endif 00137