sockets.pp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by the Free Pascal development team
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. unit Sockets;
  11. Interface
  12. {$ifdef Unix}
  13. Uses baseunix,UnixType;
  14. {$endif}
  15. {$i osdefs.inc} { Compile time defines }
  16. {$ifdef FreeBSD}
  17. {$DEFINE SOCK_HAS_SINLEN} // BSD definition of socketaddr
  18. {$endif}
  19. {$ifdef Darwin}
  20. {$DEFINE SOCK_HAS_SINLEN} // BSD definition of socketaddr
  21. {$endif}
  22. Type
  23. TSockLen = BaseUnix.TSocklen;
  24. {$i unxsockh.inc}
  25. {$i socketsh.inc}
  26. type
  27. TUnixSockAddr = packed Record
  28. {$ifdef SOCK_HAS_SINLEN}
  29. sa_len : cuchar;
  30. {$endif}
  31. family : sa_family_t;
  32. path:array[0..107] of char; //104 total for freebsd.
  33. end;
  34. const
  35. EsockEINTR = EsysEINTR;
  36. EsockEBADF = EsysEBADF;
  37. EsockEFAULT = EsysEFAULT;
  38. EsockEINVAL = EsysEINVAL;
  39. EsockEACCESS = ESysEAcces;
  40. EsockEMFILE = ESysEmfile;
  41. {$ifndef beos}
  42. EsockEMSGSIZE = ESysEMsgSize;
  43. {$endif beos}
  44. EsockENOBUFS = ESysENoBufs;
  45. EsockENOTCONN = ESysENotConn;
  46. {$ifndef beos}
  47. EsockENOTSOCK = ESysENotSock;
  48. {$endif beos}
  49. EsockEPROTONOSUPPORT = ESysEProtoNoSupport;
  50. EsockEWOULDBLOCK = ESysEWouldBlock;
  51. { unix socket specific functions }
  52. Procedure Str2UnixSockAddr(const addr:string;var t:TUnixSockAddr;var len:longint); deprecated;
  53. Function Bind(Sock:longint;const addr:string):boolean; deprecated;
  54. Function Connect(Sock:longint;const addr:string;var SockIn,SockOut:text):Boolean; deprecated;
  55. Function Connect(Sock:longint;const addr:string;var SockIn,SockOut:file):Boolean; deprecated;
  56. Function Accept(Sock:longint;var addr:string;var SockIn,SockOut:text):Boolean; deprecated;
  57. Function Accept(Sock:longint;var addr:string;var SockIn,SockOut:File):Boolean; deprecated;
  58. //function fpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint; maybelibc
  59. //function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint; maybelibc
  60. //function fpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint; maybelibc
  61. Implementation
  62. Uses {$ifndef FPC_USE_LIBC}SysCall{$else}initc{$endif};
  63. threadvar internal_socketerror : cint;
  64. { Include filerec and textrec structures }
  65. {$i filerec.inc}
  66. {$i textrec.inc}
  67. {******************************************************************************
  68. Kernel Socket Callings
  69. ******************************************************************************}
  70. function socketerror:cint;
  71. begin
  72. socketerror:=internal_socketerror;
  73. end;
  74. {$ifndef FPC_USE_LIBC}
  75. {$i unixsock.inc}
  76. {$else}
  77. {$i stdsock.inc}
  78. {$endif}
  79. {$i sockovl.inc}
  80. {$i sockets.inc}
  81. end.