SDL2.Net.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. unit SDL2.Net;
  2. (*******************************************************************************
  3. SDL2_Net.pas v1.0 29/07/2013 first version for DelphiXE
  4. v1.1 27/08/2013 add MACOS compability
  5. v1.2 31/05/2014 delete sdl2.inc
  6. Simple DirectMedia Layer
  7. Copyright (C) 1997-2013 Sam Lantinga <[email protected]>
  8. Pascal-Header-Conversion SDL from the JEDI-Team written by Domenique Louis and others.
  9. convert SDL/SDL2 to SDL2 for DelphiXE by Kotai 2013/2014 www.remakesonline.com
  10. The initial developer of this Pascal code was :
  11. Dominqiue Louis <[email protected]>
  12. *******************************************************************************)
  13. interface
  14. uses
  15. {$IFDEF MSWINDOWS}
  16. Winapi.Windows,
  17. {$ENDIF}
  18. SDL2.Import;
  19. const
  20. {$IFDEF MSWINDOWS}
  21. SDL_NetLibName = 'SDL2_net.dll';
  22. {$ENDIF}
  23. {$IFDEF ANDROID}
  24. SDL_NetLibName = 'libSDL2_net.so';
  25. {$ENDIF}
  26. {$IFDEF MACOS}
  27. {$IFDEF IOS}
  28. SDL_NetLibName = 'libSDL2_net.a';
  29. {$ELSE}
  30. SDL_NetLibName = 'SDL2_net';
  31. // SDL_NetLibName = '../Frameworks/SDL2_net.framework/Versions/A/SDL2_net';
  32. {$ENDIF}
  33. {$ENDIF}
  34. {* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL *}
  35. SDL_NET_MAJOR_VERSION = 1;
  36. {$EXTERNALSYM SDL_NET_MAJOR_VERSION}
  37. SDL_NET_MINOR_VERSION = 2;
  38. {$EXTERNALSYM SDL_NET_MINOR_VERSION}
  39. SDL_NET_PATCHLEVEL = 7;
  40. {$EXTERNALSYM SDL_NET_PATCHLEVEL}
  41. // SDL_Net.h constants
  42. {* Resolve a host name and port to an IP address in network form.
  43. If the function succeeds, it will return 0.
  44. If the host couldn't be resolved, the host portion of the returned
  45. address will be INADDR_NONE, and the function will return -1.
  46. If 'host' is NULL, the resolved host will be set to INADDR_ANY.
  47. *}
  48. INADDR_ANY = $00000000;
  49. {$EXTERNALSYM INADDR_ANY}
  50. INADDR_NONE = $FFFFFFFF;
  51. {$EXTERNALSYM INADDR_NONE}
  52. {***********************************************************************}
  53. {* UDP network API *}
  54. {***********************************************************************}
  55. {* The maximum channels on a a UDP socket *}
  56. SDLNET_MAX_UDPCHANNELS = 32;
  57. {$EXTERNALSYM SDLNET_MAX_UDPCHANNELS}
  58. {* The maximum addresses bound to a single UDP socket channel *}
  59. SDLNET_MAX_UDPADDRESSES = 4;
  60. {$EXTERNALSYM SDLNET_MAX_UDPADDRESSES}
  61. type
  62. // SDL_net.h types
  63. {***********************************************************************}
  64. {* IPv4 hostname resolution API *}
  65. {***********************************************************************}
  66. PIPAddress = ^TIPAddress;
  67. TIPAddress = record
  68. host : Uint32; // 32-bit IPv4 host address */
  69. port : Uint16; // 16-bit protocol port */
  70. end;
  71. {***********************************************************************}
  72. {* TCP network API *}
  73. {***********************************************************************}
  74. PTCPSocket = ^TTCPSocket;
  75. TTCPSocket = record
  76. ready : integer;
  77. //{$IFDEF MSWINDOWS}
  78. channel : integer;
  79. //{$ENDIF}
  80. remoteAddress : TIPaddress;
  81. localAddress : TIPaddress;
  82. sflag : integer;
  83. end;
  84. {***********************************************************************}
  85. {* UDP network API *}
  86. {***********************************************************************}
  87. PUDP_Channel = ^TUDP_Channel;
  88. TUDP_Channel = record
  89. numbound : integer;
  90. address : array[ 0..SDLNET_MAX_UDPADDRESSES - 1 ] of TIPAddress;
  91. end;
  92. PUDPSocket = ^TUDPSocket;
  93. TUDPSocket = record
  94. ready : integer;
  95. //{$IFDEF MSWINDOWS}
  96. channel : integer;
  97. //{$ENDIF}
  98. address : TIPAddress;
  99. binding : array[ 0..SDLNET_MAX_UDPCHANNELS - 1 ] of TUDP_Channel;
  100. end;
  101. PUDPpacket = ^TUDPpacket;
  102. PPUDPpacket = ^PUDPpacket;
  103. TUDPpacket = record
  104. channel : integer; {* The src/dst channel of the packet *}
  105. data : PUint8; {* The packet data *}
  106. len : integer; {* The length of the packet data *}
  107. maxlen : integer; {* The size of the data buffer *}
  108. status : integer; {* packet status after sending *}
  109. address : TIPAddress; {* The source/dest address of an incoming/outgoing packet *}
  110. end;
  111. {***********************************************************************}
  112. {* Hooks for checking sockets for available data *}
  113. {***********************************************************************}
  114. PSDLNet_Socket = ^TSDLNet_Socket;
  115. TSDLNet_Socket = record
  116. ready : integer;
  117. //{$IFDEF MSWINDOWS}
  118. channel : integer;
  119. //{$ENDIF}
  120. end;
  121. PSDLNet_SocketSet = ^TSDLNet_SocketSet;
  122. TSDLNet_SocketSet = record
  123. numsockets : integer;
  124. maxsockets : integer;
  125. sockets : PSDLNet_Socket;
  126. end;
  127. {* Any network socket can be safely cast to this socket type *}
  128. PSDLNet_GenericSocket = ^TSDLNet_GenericSocket;
  129. TSDLNet_GenericSocket = record
  130. ready : integer;
  131. end;
  132. { This macro can be used to fill a version structure with the compile-time
  133. version of the SDL_net library. }
  134. procedure SDL_NET_VERSION( var X : TSDL_version );
  135. {* Initialize/Cleanup the network API
  136. SDL must be initialized before calls to functions in this library,
  137. because this library uses utility functions from the SDL library.
  138. *}
  139. function SDLNet_Init() : integer;
  140. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_Init' {$ENDIF} {$ENDIF};
  141. procedure SDLNet_Quit();
  142. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_Quit' {$ENDIF} {$ENDIF};
  143. {* Resolve a host name and port to an IP address in network form.
  144. If the function succeeds, it will return 0.
  145. If the host couldn't be resolved, the host portion of the returned
  146. address will be INADDR_NONE, and the function will return -1.
  147. If 'host' is NULL, the resolved host will be set to INADDR_ANY.
  148. *}
  149. function SDLNet_ResolveHost( var address : TIPaddress; host : PChar; port : Uint16 ) : integer;
  150. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_ResolveHost' {$ENDIF} {$ENDIF};
  151. {* Resolve an ip address to a host name in canonical form.
  152. If the ip couldn't be resolved, this function returns NULL,
  153. otherwise a pointer to a static buffer containing the hostname
  154. is returned. Note that this function is not thread-safe.
  155. *}
  156. function SDLNet_ResolveIP( var ip : TIPaddress ) : PChar;
  157. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_ResolveIP' {$ENDIF} {$ENDIF};
  158. {***********************************************************************}
  159. {* TCP network API *}
  160. {***********************************************************************}
  161. {* Open a TCP network socket
  162. If ip.host is INADDR_NONE, this creates a local server socket on the
  163. given port, otherwise a TCP connection to the remote host and port is
  164. attempted. The address passed in should already be swapped to network
  165. byte order (addresses returned from SDLNet_ResolveHost() are already
  166. in the correct form).
  167. The newly created socket is returned, or NULL if there was an error.
  168. *}
  169. function SDLNet_TCP_Open( var ip : TIPaddress ) : PTCPSocket;
  170. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_TCP_Open' {$ENDIF} {$ENDIF};
  171. {* Accept an incoming connection on the given server socket.
  172. The newly created socket is returned, or NULL if there was an error.
  173. *}
  174. function SDLNet_TCP_Accept( server : PTCPsocket ) : PTCPSocket;
  175. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_TCP_Accept' {$ENDIF} {$ENDIF};
  176. {* Get the IP address of the remote system associated with the socket.
  177. If the socket is a server socket, this function returns NULL.
  178. *}
  179. function SDLNet_TCP_GetPeerAddress( sock : PTCPsocket ) : PIPAddress;
  180. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_TCP_GetPeerAddress' {$ENDIF} {$ENDIF};
  181. {* Send 'len' bytes of 'data' over the non-server socket 'sock'
  182. This function returns the actual amount of data sent. If the return value
  183. is less than the amount of data sent, then either the remote connection was
  184. closed, or an unknown socket error occurred.
  185. *}
  186. function SDLNet_TCP_Send( sock : PTCPsocket; data : Pointer; len : integer ) : integer;
  187. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_TCP_Send' {$ENDIF} {$ENDIF};
  188. {* Receive up to 'maxlen' bytes of data over the non-server socket 'sock',
  189. and store them in the buffer pointed to by 'data'.
  190. This function returns the actual amount of data received. If the return
  191. value is less than or equal to zero, then either the remote connection was
  192. closed, or an unknown socket error occurred.
  193. *}
  194. function SDLNet_TCP_Recv( sock : PTCPsocket; data : Pointer; maxlen : integer ) : integer;
  195. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_TCP_Recv' {$ENDIF} {$ENDIF};
  196. {* Close a TCP network socket *}
  197. procedure SDLNet_TCP_Close( sock : PTCPsocket );
  198. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_TCP_Close' {$ENDIF} {$ENDIF};
  199. {***********************************************************************}
  200. {* UDP network API *}
  201. {***********************************************************************}
  202. {* Allocate/resize/free a single UDP packet 'size' bytes long.
  203. The new packet is returned, or NULL if the function ran out of memory.
  204. *}
  205. function SDLNet_AllocPacket( size : integer ) : PUDPpacket;
  206. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_AllocPacket' {$ENDIF} {$ENDIF};
  207. function SDLNet_ResizePacket( packet : PUDPpacket; newsize : integer ) : integer;
  208. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_ResizePacket' {$ENDIF} {$ENDIF};
  209. procedure SDLNet_FreePacket( packet : PUDPpacket );
  210. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_FreePacket' {$ENDIF} {$ENDIF};
  211. {* Allocate/Free a UDP packet vector (array of packets) of 'howmany' packets,
  212. each 'size' bytes long.
  213. A pointer to the first packet in the array is returned, or NULL if the
  214. function ran out of memory.
  215. *}
  216. function SDLNet_AllocPacketV( howmany : integer; size : integer ) : PUDPpacket;
  217. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_AllocPacketV' {$ENDIF} {$ENDIF};
  218. procedure SDLNet_FreePacketV( packetV : PUDPpacket );
  219. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_FreePacketV' {$ENDIF} {$ENDIF};
  220. {* Open a UDP network socket
  221. If 'port' is non-zero, the UDP socket is bound to a local port.
  222. This allows other systems to send to this socket via a known port.
  223. *}
  224. function SDLNet_UDP_Open( port : Uint16 ) : PUDPsocket;
  225. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_UDP_Open' {$ENDIF} {$ENDIF};
  226. {* Bind the address 'address' to the requested channel on the UDP socket.
  227. If the channel is -1, then the first unbound channel will be bound with
  228. the given address as it's primary address.
  229. If the channel is already bound, this new address will be added to the
  230. list of valid source addresses for packets arriving on the channel.
  231. If the channel is not already bound, then the address becomes the primary
  232. address, to which all outbound packets on the channel are sent.
  233. This function returns the channel which was bound, or -1 on error.
  234. *}
  235. function SDLNet_UDP_Bind( sock : PUDPsocket; channel : integer; var address : TIPaddress ) : integer;
  236. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_UDP_Bind' {$ENDIF} {$ENDIF};
  237. {* Unbind all addresses from the given channel *}
  238. procedure SDLNet_UDP_Unbind( sock : PUDPsocket; channel : integer );
  239. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_UDP_Unbind' {$ENDIF} {$ENDIF};
  240. {* Get the primary IP address of the remote system associated with the
  241. socket and channel. If the channel is -1, then the primary IP port
  242. of the UDP socket is returned -- this is only meaningful for sockets
  243. opened with a specific port.
  244. If the channel is not bound and not -1, this function returns NULL.
  245. *}
  246. function SDLNet_UDP_GetPeerAddress( sock : PUDPsocket; channel : integer ) : PIPAddress;
  247. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_UDP_GetPeerAddress' {$ENDIF} {$ENDIF};
  248. {* Send a vector of packets to the the channels specified within the packet.
  249. If the channel specified in the packet is -1, the packet will be sent to
  250. the address in the 'src' member of the packet.
  251. Each packet will be updated with the status of the packet after it has
  252. been sent, -1 if the packet send failed.
  253. This function returns the number of packets sent.
  254. *}
  255. function SDLNet_UDP_SendV( sock : PUDPsocket; packets : PPUDPpacket; npackets : integer ) : integer;
  256. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_UDP_SendV' {$ENDIF} {$ENDIF};
  257. {* Send a single packet to the specified channel.
  258. If the channel specified in the packet is -1, the packet will be sent to
  259. the address in the 'src' member of the packet.
  260. The packet will be updated with the status of the packet after it has
  261. been sent.
  262. This function returns 1 if the packet was sent, or 0 on error.
  263. *}
  264. function SDLNet_UDP_Send( sock : PUDPsocket; channel : integer; packet : PUDPpacket ) : integer;
  265. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_UDP_Send' {$ENDIF} {$ENDIF};
  266. {* Receive a vector of pending packets from the UDP socket.
  267. The returned packets contain the source address and the channel they arrived
  268. on. If they did not arrive on a bound channel, the the channel will be set
  269. to -1.
  270. The channels are checked in highest to lowest order, so if an address is
  271. bound to multiple channels, the highest channel with the source address
  272. bound will be returned.
  273. This function returns the number of packets read from the network, or -1
  274. on error. This function does not block, so can return 0 packets pending.
  275. *}
  276. function SDLNet_UDP_RecvV( sock : PUDPsocket; packets : PPUDPpacket ) : integer;
  277. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_UDP_RecvV' {$ENDIF} {$ENDIF};
  278. {* Receive a single packet from the UDP socket.
  279. The returned packet contains the source address and the channel it arrived
  280. on. If it did not arrive on a bound channel, the the channel will be set
  281. to -1.
  282. The channels are checked in highest to lowest order, so if an address is
  283. bound to multiple channels, the highest channel with the source address
  284. bound will be returned.
  285. This function returns the number of packets read from the network, or -1
  286. on error. This function does not block, so can return 0 packets pending.
  287. *}
  288. function SDLNet_UDP_Recv( sock : PUDPsocket; packet : PUDPpacket ) : integer;
  289. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_UDP_Recv' {$ENDIF} {$ENDIF};
  290. {* Close a UDP network socket *}
  291. procedure SDLNet_UDP_Close( sock : PUDPsocket );
  292. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_UDP_Close' {$ENDIF} {$ENDIF};
  293. {***********************************************************************}
  294. {* Hooks for checking sockets for available data *}
  295. {***********************************************************************}
  296. {* Allocate a socket set for use with SDLNet_CheckSockets()
  297. This returns a socket set for up to 'maxsockets' sockets, or NULL if
  298. the function ran out of memory.
  299. *}
  300. function SDLNet_AllocSocketSet( maxsockets : integer ) : PSDLNet_SocketSet;
  301. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_AllocSocketSet' {$ENDIF} {$ENDIF};
  302. {* Add a socket to a set of sockets to be checked for available data *}
  303. function SDLNet_AddSocket( set_ : PSDLNet_SocketSet; sock : PSDLNet_GenericSocket ) : integer;
  304. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_AddSocket' {$ENDIF} {$ENDIF};
  305. function SDLNet_TCP_AddSocket( set_ : PSDLNet_SocketSet; sock : PTCPSocket ) : integer;
  306. function SDLNet_UDP_AddSocket( set_ : PSDLNet_SocketSet; sock : PUDPSocket ) : integer;
  307. {* Remove a socket from a set of sockets to be checked for available data *}
  308. function SDLNet_DelSocket( set_ : PSDLNet_SocketSet; sock : PSDLNet_GenericSocket ) : integer;
  309. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_DelSocket' {$ENDIF} {$ENDIF};
  310. function SDLNet_TCP_DelSocket( set_ : PSDLNet_SocketSet; sock : PTCPSocket ) : integer;
  311. function SDLNet_UDP_DelSocket( set_ : PSDLNet_SocketSet; sock : PUDPSocket ) : integer;
  312. {* This function checks to see if data is available for reading on the
  313. given set of sockets. If 'timeout' is 0, it performs a quick poll,
  314. otherwise the function returns when either data is available for
  315. reading, or the timeout in milliseconds has elapsed, which ever occurs
  316. first. This function returns the number of sockets ready for reading,
  317. or -1 if there was an error with the select() system call.
  318. *}
  319. function SDLNet_CheckSockets( set_ : PSDLNet_SocketSet; timeout : Sint32 ) : integer;
  320. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_CheckSockets' {$ENDIF} {$ENDIF};
  321. {* After calling SDLNet_CheckSockets(), you can use this function on a
  322. socket that was in the socket set, to find out if data is available
  323. for reading.
  324. *}
  325. function SDLNet_SocketReady( sock : PSDLNet_GenericSocket ) : boolean;
  326. {* Free a set of sockets allocated by SDL_NetAllocSocketSet() *}
  327. procedure SDLNet_FreeSocketSet( set_ : PSDLNet_SocketSet );
  328. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_FreeSocketSet' {$ENDIF} {$ENDIF};
  329. {***********************************************************************}
  330. {* Platform-independent data conversion functions *}
  331. {***********************************************************************}
  332. {* Write a 16/32 bit value to network packet buffer *}
  333. procedure SDLNet_Write16( value : Uint16; area : Pointer );
  334. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_Write16' {$ENDIF} {$ENDIF};
  335. procedure SDLNet_Write32( value : Uint32; area : Pointer );
  336. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_Write32' {$ENDIF} {$ENDIF};
  337. {* Read a 16/32 bit value from network packet buffer *}
  338. function SDLNet_Read16( area : Pointer ) : Uint16;
  339. //{$IFNDEF CPUARM}
  340. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_Read16' {$ENDIF} {$ENDIF};
  341. //{$ENDIF}
  342. function SDLNet_Read32( area : Pointer ) : Uint32;
  343. //{$IFNDEF CPUARM}
  344. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_Read32' {$ENDIF} {$ENDIF};
  345. //{$ENDIF}
  346. {***********************************************************************}
  347. {* Error reporting functions *}
  348. {***********************************************************************}
  349. {* We'll use SDL's functions for error reporting *}
  350. procedure SDLNet_SetError( fmt : PChar );
  351. function SDLNet_GetError() : PChar;
  352. (* I'm eventually going to try to disentangle SDL_net from SDL, thus making
  353. SDL_net an independent X-platform networking toolkit. Not today though....
  354. proceudre SDLNet_SetError(const char *fmt, ...);
  355. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_SetError' {$ENDIF} {$ENDIF};
  356. function SDLNet_GetError() : PChar;
  357. cdecl; external SDL_NetLibName {$IFDEF MACOS} {$IFNDEF IOS} name '_SDLNet_GetError' {$ENDIF} {$ENDIF};
  358. *)
  359. //******************************************************************************
  360. //******************************************************************************
  361. //******************************************************************************
  362. //******************************************************************************
  363. //******************************************************************************
  364. implementation
  365. //******************************************************************************
  366. procedure SDL_NET_VERSION( var X : TSDL_version );
  367. begin
  368. X.major := SDL_NET_MAJOR_VERSION;
  369. X.minor := SDL_NET_MINOR_VERSION;
  370. X.patch := SDL_NET_PATCHLEVEL;
  371. end;
  372. //******************************************************************************
  373. function SDLNet_TCP_AddSocket( set_ : PSDLNet_SocketSet; sock : PTCPSocket ) : integer;
  374. begin
  375. result := SDLNet_AddSocket( set_, PSDLNet_GenericSocket( sock ) );
  376. end;
  377. //******************************************************************************
  378. function SDLNet_UDP_AddSocket( set_ : PSDLNet_SocketSet; sock : PUDPSocket ) : integer;
  379. begin
  380. result := SDLNet_AddSocket( set_, PSDLNet_GenericSocket( sock ) );
  381. end;
  382. //******************************************************************************
  383. function SDLNet_TCP_DelSocket( set_ : PSDLNet_SocketSet; sock : PTCPSocket ) : integer;
  384. begin
  385. result := SDLNet_DelSocket( set_, PSDLNet_GenericSocket( sock ) );
  386. end;
  387. //******************************************************************************
  388. function SDLNet_UDP_DelSocket( set_ : PSDLNet_SocketSet; sock : PUDPSocket ) : integer;
  389. begin
  390. result := SDLNet_DelSocket( set_, PSDLNet_GenericSocket( sock ) );
  391. end;
  392. //******************************************************************************
  393. {* After calling SDLNet_CheckSockets(), you can use this function on a
  394. socket that was in the socket set, to find out if data is available
  395. for reading.
  396. *}
  397. function SDLNet_SocketReady( sock : PSDLNet_GenericSocket ) : boolean;
  398. begin
  399. result := ( ( sock <> nil ) and ( sock^.ready = 1 ) );
  400. end;
  401. //******************************************************************************
  402. procedure SDLNet_SetError( fmt : PChar );
  403. begin
  404. SDL_SetError( fmt );
  405. end;
  406. //******************************************************************************
  407. function SDLNet_GetError() : PChar;
  408. begin
  409. result := SDL_GetError;
  410. end;
  411. //******************************************************************************
  412. //{$IFDEF CPUARM}
  413. //function SDLNet_Read16( area : Pointer ) : Uint16;
  414. //begin
  415. // result := ((PUint8(area)^ shl 8) or (PUint8(area+1)^ shl 0));
  416. //end;
  417. //******************************************************************************
  418. //function SDLNet_Read32( area : Pointer ) : Uint32;
  419. //begin
  420. // result := ((PUint8(area)^ shl 24) or (PUint8(area+1)^ shl 16) or (PUint8(area+2)^ shl 8) or (PUint8(area+3)^ shl 0) );
  421. //end;
  422. //{$ENDIF}
  423. end.