99interface
1010
1111uses
12- SysUtils, DateUtils, classes, xpr.Types, xpr.CompilerContext;
12+ SysUtils, DateUtils, classes, serial, sockets, xpr.Types, xpr.CompilerContext;
1313
1414procedure ImportExternalMethods (ctx: TCompilerContext);
1515procedure ImportSystemModules (ctx: TCompilerContext);
@@ -244,7 +244,7 @@ 'type TMemoryManager = record' + LineEnding +
244244 TCS.Name := ' TCriticalSection' ;
245245 ctx.AddManagedType(TCS);
246246 ctx.AddType(' TCriticalSection' , TCS);
247- ctx.AddExternalMethod(@_CSInit, ' Init ' , TCS, [], [], TCS);
247+ ctx.AddExternalMethod(@_CSInit, ' Create ' , TCS, [], [], TCS);
248248 ctx.AddExternalMethod(@_CSDestroy, ' Destroy' , TCS, [], [], nil );
249249 ctx.AddExternalMethod(@_CSLock, ' Lock' , TCS, [], [], nil );
250250 ctx.AddExternalMethod(@_CSUnlock, ' Unlock' , TCS, [], [], nil );
@@ -255,6 +255,104 @@ 'type TMemoryManager = record' + LineEnding +
255255 ctx.AddExternalFunc(@_FreeLib, ' FreeLib' , [tInt], [pbCopy], nil );
256256 ctx.AddExternalFunc(@_GetProc, ' GetProc' , [tInt, tString], [pbCopy, pbCopy], tInt);
257257 ctx.AddExternalFunc(@_FreeCallback, ' free_callback' , [tInt], [pbCopy], nil );
258+
259+
260+ // --- Sockets & Serial -------------------
261+ ctx.ParseNativeDecls(
262+ // --- Types ---
263+ ' type TSerialParity = enum(NoneParity, OddParity, EvenParity, MarkParity, SpaceParity)' + LineEnding +
264+ // --- Socket constants ---
265+ ' const AF_INET: Int32 = 2' + LineEnding +
266+ ' const AF_INET6: Int32 = 10' + LineEnding +
267+ ' const AF_UNIX: Int32 = 1' + LineEnding +
268+
269+ ' const SOCK_STREAM: Int32 = 1' + LineEnding +
270+ ' const SOCK_DGRAM: Int32 = 2' + LineEnding +
271+ ' const SOCK_RAW: Int32 = 3' + LineEnding +
272+
273+ ' const IPPROTO_TCP: Int32 = 6' + LineEnding +
274+ ' const IPPROTO_UDP: Int32 = 17' + LineEnding +
275+
276+ ' const SOL_SOCKET: Int32 = 1' + LineEnding +
277+
278+ ' const SO_REUSEADDR:Int32 = 2' + LineEnding +
279+ ' const SO_KEEPALIVE:Int32 = 9' + LineEnding +
280+ ' const SO_RCVBUF: Int32 = 8' + LineEnding +
281+ ' const SO_SNDBUF: Int32 = 7' + LineEnding +
282+ ' const SO_RCVTIMEO: Int32 = 20' + LineEnding +
283+ ' const SO_SNDTIMEO: Int32 = 21' + LineEnding +
284+
285+ ' const SHUT_RD: Int32 = 0' + LineEnding +
286+ ' const SHUT_WR: Int32 = 1' + LineEnding +
287+ ' const SHUT_RDWR: Int32 = 2' + LineEnding +
288+
289+ ' const INADDR_ANY: Int32 = 0' + LineEnding +
290+ ' const INADDR_LOOPBACK: Int32 = $7F000001' + LineEnding +
291+ ' const INADDR_BROADCAST: Int32 = $FFFFFFFF' + LineEnding +
292+
293+ ' const MSG_PEEK: Int32 = 2' + LineEnding +
294+ ' const MSG_WAITALL: Int32 = 256' + LineEnding +
295+ ' const MSG_DONTWAIT: Int32 = 64' + LineEnding +
296+
297+ // --- Sockets ---
298+ ' func fpSocket(domain, typ, protocol: Int32): Int32' + LineEnding +
299+ ' func fpConnect(sockfd: Int32; addr: Pointer; addrlen: Int32): Int32' + LineEnding +
300+ ' func fpBind(sockfd: Int32; addr: Pointer; addrlen: Int32): Int32' + LineEnding +
301+ ' func fpListen(sockfd: Int32; backlog: Int32): Int32' + LineEnding +
302+ ' func fpAccept(sockfd: Int32; addr: Pointer; ref addrlen: Int32): Int32' + LineEnding +
303+ ' func fpRecv(sockfd: Int32; buf: Pointer; len, flags: Int32): Int32' + LineEnding +
304+ ' func fpRecvFrom(sockfd: Int32; buf: Pointer; len, flags: Int32; addr: Pointer; ref addrlen: Int32): Int32' + LineEnding +
305+ ' func fpSend(sockfd: Int32; buf: Pointer; len, flags: Int32): Int32' + LineEnding +
306+ ' func fpSendTo(sockfd: Int32; buf: Pointer; len, flags: Int32; addr: Pointer; addrlen: Int32): Int32' + LineEnding +
307+ ' func fpClose(sockfd: Int32): Int32' + LineEnding +
308+ ' func fpSetSockOpt(sockfd, level, optname: Int32; optval: Pointer; optlen: Int32): Int32' + LineEnding +
309+ ' func fpGetSockOpt(sockfd, level, optname: Int32; optval: Pointer; ref optlen: Int32): Int32' + LineEnding +
310+ ' func fpSelect(nfds: Int32; readfds, writefds, exceptfds: Pointer; timeout: Pointer): Int32' + LineEnding +
311+ ' func fpShutdown(sockfd, how: Int32): Int32' + LineEnding +
312+
313+ // --- Byte order ---
314+ ' func htons(v: UInt16): UInt16' + LineEnding +
315+ ' func htonl(v: UInt32): UInt32' + LineEnding +
316+ ' func ntohs(v: UInt16): UInt16' + LineEnding +
317+ ' func ntohl(v: UInt32): UInt32' + LineEnding +
318+
319+ // --- Serial ---
320+ ' func SerOpen(device: string): Int32' + LineEnding +
321+ ' func SerClose(handle: Int32)' + LineEnding +
322+ ' func SerSetParams(handle: Int32; baud, bits: Int32; parity: TSerialParity; stopBits: Int32; flags: Int32)' + LineEnding +
323+ ' func SerRead(handle: Int32; buffer: Pointer; count: Int32): Int32' + LineEnding +
324+ ' func SerWrite(handle: Int32; buffer: Pointer; count: Int32): Int32' + LineEnding +
325+ ' func SerSync(handle: Int32)' + LineEnding +
326+ ' func SerFlushOutput(handle: Int32)' + LineEnding,
327+
328+ [Bind(' fpSocket' , @_fpSocket),
329+ Bind(' fpConnect' , @_fpConnect),
330+ Bind(' fpBind' , @_fpBind),
331+ Bind(' fpListen' , @_fpListen),
332+ Bind(' fpAccept' , @_fpAccept),
333+ Bind(' fpRecv' , @_fpRecv),
334+ Bind(' fpRecvFrom' , @_fpRecvFrom),
335+ Bind(' fpSend' , @_fpSend),
336+ Bind(' fpSendTo' , @_fpSendTo),
337+ Bind(' fpClose' , @_fpClose),
338+ Bind(' fpSetSockOpt' , @_fpSetSockOpt),
339+ Bind(' fpGetSockOpt' , @_fpGetSockOpt),
340+ Bind(' fpSelect' , @_fpSelect),
341+ Bind(' fpShutdown' , @_fpShutdown),
342+
343+ Bind(' htons' , @_htons),
344+ Bind(' htonl' , @_htonl),
345+ Bind(' ntohs' , @_ntohs),
346+ Bind(' ntohl' , @_ntohl),
347+
348+ Bind(' SerOpen' , @_SerOpen),
349+ Bind(' SerClose' , @_SerClose),
350+ Bind(' SerSetParams' , @_SerSetParams),
351+ Bind(' SerRead' , @_SerRead),
352+ Bind(' SerWrite' , @_SerWrite),
353+ Bind(' SerSync' , @_SerSync),
354+ Bind(' SerFlushOutput' , @_SerFlushOutput)]
355+ );
258356end ;
259357
260358
0 commit comments