sockets.pp 3.0 KB

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