sockets.pp 3.0 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. {$if
  17. defined(FreeBSD) or
  18. defined(Darwin) or
  19. defined(Haiku)
  20. }
  21. {$DEFINE SOCK_HAS_SINLEN} // BSD definition of socketaddr
  22. {$endif}
  23. Type
  24. TSockLen = BaseUnix.TSocklen;
  25. {$i unxsockh.inc}
  26. {$i socketsh.inc}
  27. type
  28. TUnixSockAddr = packed Record
  29. {$ifdef SOCK_HAS_SINLEN}
  30. sa_len : cuchar;
  31. {$endif}
  32. family : sa_family_t;
  33. path:array[0..107] of char; //104 total for freebsd.
  34. end;
  35. const
  36. EsockEINTR = EsysEINTR;
  37. EsockEBADF = EsysEBADF;
  38. EsockEFAULT = EsysEFAULT;
  39. EsockEINVAL = EsysEINVAL;
  40. EsockEACCESS = ESysEAcces;
  41. EsockEMFILE = ESysEmfile;
  42. {$ifndef beos}
  43. EsockEMSGSIZE = ESysEMsgSize;
  44. {$endif beos}
  45. EsockENOBUFS = ESysENoBufs;
  46. EsockENOTCONN = ESysENotConn;
  47. {$ifndef beos}
  48. EsockENOTSOCK = ESysENotSock;
  49. {$endif beos}
  50. EsockEPROTONOSUPPORT = ESysEProtoNoSupport;
  51. EsockEWOULDBLOCK = ESysEWouldBlock;
  52. { unix socket specific functions }
  53. Procedure Str2UnixSockAddr(const addr:string;var t:TUnixSockAddr;var len:longint); deprecated;
  54. Function Bind(Sock:longint;const addr:string):boolean; deprecated;
  55. Function Connect(Sock:longint;const addr:string;var SockIn,SockOut:text):Boolean; deprecated;
  56. Function Connect(Sock:longint;const addr:string;var SockIn,SockOut:file):Boolean; deprecated;
  57. Function Accept(Sock:longint;var addr:string;var SockIn,SockOut:text):Boolean; deprecated;
  58. Function Accept(Sock:longint;var addr:string;var SockIn,SockOut:File):Boolean; deprecated;
  59. //function fpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint; maybelibc
  60. //function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint; maybelibc
  61. //function fpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint; maybelibc
  62. Implementation
  63. Uses {$ifndef FPC_USE_LIBC}SysCall{$else}initc{$endif};
  64. threadvar internal_socketerror : cint;
  65. { Include filerec and textrec structures }
  66. {$i filerec.inc}
  67. {$i textrec.inc}
  68. {******************************************************************************
  69. Kernel Socket Callings
  70. ******************************************************************************}
  71. function socketerror:cint;
  72. begin
  73. socketerror:=internal_socketerror;
  74. end;
  75. {$ifndef FPC_USE_LIBC}
  76. {$i unixsock.inc}
  77. {$else}
  78. {$i stdsock.inc}
  79. {$endif}
  80. {$i sockovl.inc}
  81. {$i sockets.inc}
  82. end.