sockets.tex 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. %
  2. % $Id$
  3. % This file is part of the FPC documentation.
  4. % Copyright (C) 1997, by Michael Van Canneyt
  5. %
  6. % The FPC documentation is free text; you can redistribute it and/or
  7. % modify it under the terms of the GNU Library General Public License as
  8. % published by the Free Software Foundation; either version 2 of the
  9. % License, or (at your option) any later version.
  10. %
  11. % The FPC Documentation is distributed in the hope that it will be useful,
  12. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. % Library General Public License for more details.
  15. %
  16. % You should have received a copy of the GNU Library General Public
  17. % License along with the FPC documentation; see the file COPYING.LIB. If not,
  18. % write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. % Boston, MA 02111-1307, USA.
  20. %
  21. \chapter{The SOCKETS unit.}
  22. This chapter describes the SOCKETS unit for Free Pascal.
  23. it was written for \linux by Micha\"el Van Canneyt, and ported to \windows
  24. by Florian Klaempfl.
  25. The chapter is divided in 2 sections:
  26. \begin{itemize}
  27. \item The first section lists types, constants and variables from the
  28. interface part of the unit.
  29. \item The second section describes the functions defined in the unit.
  30. \end{itemize}
  31. \section {Types, Constants and variables : }
  32. The following constants identify the different socket types, as needed in
  33. the \seef{Socket} call.
  34. \begin{verbatim}
  35. SOCK_STREAM = 1; { stream (connection) socket }
  36. SOCK_DGRAM = 2; { datagram (conn.less) socket }
  37. SOCK_RAW = 3; { raw socket }
  38. SOCK_RDM = 4; { reliably-delivered message }
  39. SOCK_SEQPACKET = 5; { sequential packet socket }
  40. SOCK_PACKET =10;
  41. \end{verbatim}
  42. The following constants determine the socket domain, they are used in the
  43. \seef{Socket} call.
  44. \begin{verbatim}
  45. AF_UNSPEC = 0;
  46. AF_UNIX = 1; { Unix domain sockets }
  47. AF_INET = 2; { Internet IP Protocol }
  48. AF_AX25 = 3; { Amateur Radio AX.25 }
  49. AF_IPX = 4; { Novell IPX }
  50. AF_APPLETALK = 5; { Appletalk DDP }
  51. AF_NETROM = 6; { Amateur radio NetROM }
  52. AF_BRIDGE = 7; { Multiprotocol bridge }
  53. AF_AAL5 = 8; { Reserved for Werner's ATM }
  54. AF_X25 = 9; { Reserved for X.25 project }
  55. AF_INET6 = 10; { IP version 6 }
  56. AF_MAX = 12;
  57. \end{verbatim}
  58. The following constants determine the protocol family, they are used in the
  59. \seef{Socket} call.
  60. \begin{verbatim}
  61. PF_UNSPEC = AF_UNSPEC;
  62. PF_UNIX = AF_UNIX;
  63. PF_INET = AF_INET;
  64. PF_AX25 = AF_AX25;
  65. PF_IPX = AF_IPX;
  66. PF_APPLETALK = AF_APPLETALK;
  67. PF_NETROM = AF_NETROM;
  68. PF_BRIDGE = AF_BRIDGE;
  69. PF_AAL5 = AF_AAL5;
  70. PF_X25 = AF_X25;
  71. PF_INET6 = AF_INET6;
  72. PF_MAX = AF_MAX;
  73. \end{verbatim}
  74. The following types are used to store different kinds of eddresses for the
  75. \seef{Bind}, \seef{Recv} and \seef{Send} calls.
  76. \begin{verbatim}
  77. TSockAddr = packed Record
  78. family:word;
  79. data :array [0..13] of char;
  80. end;
  81. TUnixSockAddr = packed Record
  82. family:word;
  83. path:array[0..108] of char;
  84. end;
  85. TInetSockAddr = packed Record
  86. family:Word;
  87. port :Word;
  88. addr :Cardinal;
  89. pad :array [1..8] of byte;
  90. end;
  91. \end{verbatim}
  92. The following type is returned by the \seef{SocketPair} call.
  93. \begin{verbatim}
  94. TSockArray = Array[1..2] of Longint;
  95. \end{verbatim}
  96. \section {Functions and Procedures}
  97. \begin{function}{Accept}
  98. \Declaration
  99. Function Accept (Sock:Longint;Var Addr;Var Addrlen:Longint) : Longint;
  100. \Description
  101. \var{Accept} accepts a connection from a socket \var{Sock}, which was
  102. listening for a connection. If a connection is accepted, a file descriptor
  103. is returned. On error \var{-1} is returned. The returned socket may NOT
  104. be used to accept more connections. The original socket remains open.
  105. The \var{Accept} call fills the address of the connecting entity in
  106. \var{Addr}, and sets its length in \var{Addrlen}. \var{Addr} should
  107. be pointing to enough space, and \var{Addrlen} should be set to the
  108. amount of space available, prior to the call.
  109. \Errors
  110. On error, \var{-1} is returned, and errors are reported in
  111. \var{SocketError}, and include the following:
  112. \begin{description}
  113. \item[SYS\_EBADF] The socket descriptor is invalid.
  114. \item[SYS\_ENOTSOCK] The descriptor is not a socket.
  115. \item[SYS\_EOPNOTSUPP] The socket type doesn't support the \var{Listen}
  116. operation.
  117. \item[SYS\_EFAULT] \var{Addr} points outside your address space.
  118. \item[SYS\_EWOULDBLOCK] The requested operation would block the process.
  119. \end{description}
  120. \SeeAlso
  121. \seef{Listen}, \seef{Connect}
  122. \end{function}
  123. \latex{\lstinputlisting{sockex/socksvr.pp}}
  124. \html{\input{sockex/socksvr.tex}}
  125. \begin{functionl}{Accept}{AltAAccept}
  126. \Declaration
  127. Function Accept (Sock:longint;var addr:string;var SockIn,SockOut:text) : Boolean;
  128. \Description
  129. This is an alternate form of the \seef{Accept} command. It is equivalent
  130. to subsequently calling the regular \seef{Accept}
  131. function and the \seep{Sock2Text} function.
  132. The function returns \var{True} if successfull, \var{False} otherwise.
  133. \Errors
  134. The errors are those of \seef{Accept}.
  135. \SeeAlso
  136. \seef{Accept}
  137. \end{functionl}
  138. \begin{functionl}{Accept}{AltBAccept}
  139. \Declaration
  140. Function Accept (Sock:longint;var addr:string;var SockIn,SockOut:File) : Boolean;
  141. \Description
  142. This is an alternate form of the \seef{Accept} command.
  143. It is equivalent
  144. to subsequently calling the regular \seef{Accept} function and the
  145. \seep{Sock2File} function.
  146. The \var{Addr} parameter contains the name of the unix socket file to be
  147. opened.
  148. The function returns \var{True} if successfull, \var{False} otherwise.
  149. \Errors
  150. The errors are those of \seef{Accept}.
  151. \SeeAlso
  152. \seef{Accept}
  153. \end{functionl}
  154. \begin{functionl}{Accept}{AltCAccept}
  155. \Declaration
  156. Function Accept (Sock:longint;var addr:TInetSockAddr;var SockIn,SockOut:File) : Boolean;
  157. \Description
  158. This is an alternate form of the \seef{Accept} command.
  159. It is equivalent
  160. to subsequently calling the regular \seef{Accept} function and the
  161. \seep{Sock2File} function.
  162. The \var{Addr} parameter contains the parameters of the internet socket that
  163. should be opened.
  164. The function returns \var{True} if successfull, \var{False} otherwise.
  165. \Errors
  166. The errors are those of \seef{Accept}.
  167. \SeeAlso
  168. \seef{Accept}
  169. \end{functionl}
  170. \begin{function}{Bind}
  171. \Declaration
  172. Function Bind (Sock:Longint;Var Addr;AddrLen:Longint) : Boolean;
  173. \Description
  174. \var{Bind} binds the socket \var{Sock} to address \var{Addr}. \var{Addr}
  175. has length \var{Addrlen}.
  176. The function returns \var{True} if the call was succesful, \var{False} if
  177. not.
  178. \Errors
  179. Errors are returned in \var{SocketError} and include the following:
  180. \begin{description}
  181. \item[SYS\_EBADF] The socket descriptor is invalid.
  182. \item[SYS\_EINVAL] The socket is already bound to an address,
  183. \item[SYS\_EACCESS] Address is protected and you don't have permission to
  184. open it.
  185. \end{description}
  186. More arrors can be found in the Unix man pages.
  187. \SeeAlso
  188. \seef{Socket}
  189. \end{function}
  190. \begin{functionl}{Bind}{AltBind}
  191. \Declaration
  192. Function Bind (Sock:longint;const addr:string) : boolean;
  193. \Description
  194. This is an alternate form of the \var{Bind} command.
  195. This form of the \var{Bind} command is equivalent to subsequently
  196. calling \seep{Str2UnixSockAddr} and the regular \seef{Bind} function.
  197. The function returns \var{True} if successfull, \var{False} otherwise.
  198. \Errors
  199. Errors are those of the regular \seef{Bind} command.
  200. \SeeAlso
  201. \seef{Bind}
  202. \end{functionl}
  203. \begin{function}{Connect}
  204. \Declaration
  205. Function Connect (Sock:Longint;Var Addr;Addrlen:Longint) : Longint;
  206. \Description
  207. \var{Connect} opens a connection to a peer, whose address is described by
  208. \var{Addr}. \var{AddrLen} contains the length of the address.
  209. The type of \var{Addr} depends on the kind of connection you're trying to
  210. make, but is generally one of \var{TSockAddr} or \var{TUnixSockAddr}.
  211. The \var{Connect} function returns a file descriptor if the call
  212. was successfull, \var{-1} in case of error.
  213. \Errors
  214. On error, \var{-1} is returned and errors are reported in
  215. \var{SocketError}.
  216. \SeeAlso
  217. \seef{Listen}, \seef{Bind},\seef{Accept}
  218. \end{function}
  219. \latex{\lstinputlisting{sockex/sockcli.pp}}
  220. \html{\input{sockex/sockcli.tex}}
  221. \begin{functionl}{Connect}{AltAConnect}
  222. \Declaration
  223. Function Connect (Sock:longint;const addr:string;var SockIn,SockOut:text) : Boolean;
  224. \Description
  225. This is an alternate form of the \seef{Connect} command.
  226. It is equivalent to subsequently calling the regular \seef{Connect}
  227. function and the \seep{Sock2Text} function.
  228. The function returns \var{True} if successfull, \var{False} otherwise.
  229. \Errors
  230. The errors are those of \seef{Connect}.
  231. \SeeAlso
  232. \seef{Connect}
  233. \end{functionl}
  234. \begin{functionl}{Connect}{AltBConnect}
  235. \Declaration
  236. Function Connect (Sock:longint;const addr:string;var SockIn,SockOut:file) : Boolean;
  237. \Description
  238. This is an alternate form of the \seef{Connect} command. The parameter
  239. \var{addr} contains the name of the unix socket file to be opened.
  240. It is equivalent to subsequently calling the regular \seef{Connect}
  241. function and the \seep{Sock2File} function.
  242. The function returns \var{True} if successfull, \var{False} otherwise.
  243. \Errors
  244. The errors are those of \seef{Connect}.
  245. \SeeAlso
  246. \seef{Connect}
  247. \end{functionl}
  248. \begin{functionl}{Connect}{AltCConnect}
  249. \Declaration
  250. Function Connect (Sock:longint;const addr: TInetSockAddr;var SockIn,SockOut:file) : Boolean;
  251. \Description
  252. This is another alternate form of the \seef{Connect} command.
  253. It is equivalent
  254. to subsequently calling the regular \seef{Connect} function and the
  255. \seep{Sock2File} function. The \var{Addr} parameter contains the parameters
  256. of the internet socket to connect to.
  257. The function returns \var{True} if successfull, \var{False} otherwise.
  258. \Errors
  259. The errors are those of \seef{Connect}.
  260. \SeeAlso
  261. \seef{Connect}
  262. \end{functionl}
  263. \latex{\lstinputlisting{sockex/pfinger.pp}}
  264. \html{\input{sockex/pfinger.tex}}
  265. \begin{function}{GetPeerName}
  266. \Declaration
  267. Function GetPeerName (Sock:Longint;Var Addr;Var Addrlen:Longint) : Longint;
  268. \Description
  269. \var{GetPeerName} returns the name of the entity connected to the
  270. specified socket \var{Sock}. The Socket must be connected for this call to
  271. work.
  272. \var{Addr} should point to enough space to store the name, the
  273. amount of space pointed to should be set in \var{Addrlen}.
  274. When the function returns succesfully, \var{Addr} will be filled with the
  275. name, and \var{Addrlen} will be set to the length of \var{Addr}.
  276. \Errors
  277. Errors are reported in \var{SocketError}, and include the following:
  278. \begin{description}
  279. \item[SYS\_EBADF] The socket descriptor is invalid.
  280. \item[SYS\_ENOBUFS] The system doesn't have enough buffers to perform the
  281. operation.
  282. \item[SYS\_ENOTSOCK] The descriptor is not a socket.
  283. \item[SYS\_EFAULT] \var{Addr} points outside your address space.
  284. \item[SYS\_ENOTCONN] The socket isn't connected.
  285. \end{description}
  286. \SeeAlso
  287. \seef{Connect}, \seef{Socket}, \seem{connect}{2}
  288. \end{function}
  289. \begin{function}{GetSocketName}
  290. \Declaration
  291. Function GetSocketName (Sock:Longint;Var Addr;Var Addrlen:Longint) : Longint;
  292. \Description
  293. \var{GetSockName} returns the current name of the specified socket
  294. \var{Sock}. \var{Addr} should point to enough space to store the name, the
  295. amount of space pointed to should be set in \var{Addrlen}.
  296. When the function returns succesfully, \var{Addr} will be filled with the
  297. name, and \var{Addrlen} will be set to the length of \var{Addr}.
  298. \Errors
  299. Errors are reported in \var{SocketError}, and include the following:
  300. \begin{description}
  301. \item[SYS\_EBADF] The socket descriptor is invalid.
  302. \item[SYS\_ENOBUFS] The system doesn't have enough buffers to perform the
  303. operation.
  304. \item[SYS\_ENOTSOCK] The descriptor is not a socket.
  305. \item[SYS\_EFAULT] \var{Addr} points outside your address space.
  306. \end{description}
  307. \SeeAlso
  308. \seef{Bind}
  309. \end{function}
  310. \begin{function}{GetSocketOptions}
  311. \Declaration
  312. Function GetSocketOptions (Sock,Level,OptName:Longint;Var OptVal;optlen:longint) : Longint;
  313. \Description
  314. \var{GetSocketOptions} gets the connection options for socket \var{Sock}.
  315. The socket may be obtained from different levels, indicated by \var{Level},
  316. which can be one of the following:
  317. \begin{description}
  318. \item[SOL\_SOCKET] From the socket itself.
  319. \item[XXX] set \var{Level} to \var{XXX}, the protocol number of the protocol
  320. which should interprete the option.
  321. \end{description}
  322. For more information on this call, refer to the unix manual page \seem{getsockopt}{2}.
  323. \Errors
  324. Errors are reported in \var{SocketError}, and include the following:
  325. \begin{description}
  326. \item[SYS\_EBADF] The socket descriptor is invalid.
  327. \item[SYS\_ENOTSOCK] The descriptor is not a socket.
  328. \item[SYS\_EFAULT] \var{OptVal} points outside your address space.
  329. \end{description}
  330. \SeeAlso
  331. \seef{GetSocketOptions}
  332. \end{function}
  333. \begin{function}{Listen}
  334. \Declaration
  335. Function Listen (Sock,MaxConnect:Longint) : Boolean;
  336. \Description
  337. \var{Listen} listens for up to \var{MaxConnect} connections from socket
  338. \var{Sock}. The socket \var{Sock} must be of type \var{SOCK\_STREAM} or
  339. \var{Sock\_SEQPACKET}.
  340. The function returns \var{True} if a connection was accepted, \var{False}
  341. if an error occurred.
  342. \Errors
  343. Errors are reported in \var{SocketError}, and include the following:
  344. \begin{description}
  345. \item[SYS\_EBADF] The socket descriptor is invalid.
  346. \item[SYS\_ENOTSOCK] The descriptor is not a socket.
  347. \item[SYS\_EOPNOTSUPP] The socket type doesn't support the \var{Listen}
  348. operation.
  349. \end{description}
  350. \SeeAlso
  351. \seef{Socket}, \seef{Bind}, \seef{Connect}
  352. \end{function}
  353. \begin{function}{Recv}
  354. \Declaration
  355. Function Recv (Sock:Longint;Var Addr;AddrLen,Flags:Longint) : Longint;
  356. \Description
  357. \var{Recv} reads at most \var{Addrlen} bytes from socket \var{Sock} into
  358. address \var{Addr}. The socket must be in a connected state.
  359. \var{Flags} can be one of the following:
  360. \begin{description}
  361. \item [1] : Process out-of band data.
  362. \item [4] : Bypass routing, use a direct interface.
  363. \item [??] : Wait for full request or report an error.
  364. \end{description}
  365. The functions returns the number of bytes actually read from the socket, or
  366. -1 if a detectable error occurred.
  367. \Errors
  368. Errors are reported in \var{SocketError}, and include the following:
  369. \begin{description}
  370. \item[SYS\_EBADF] The socket descriptor is invalid.
  371. \item[SYS\_ENOTCONN] The socket isn't connected.
  372. \item[SYS\_ENOTSOCK] The descriptor is not a socket.
  373. \item[SYS\_EFAULT] The address is outside your address space.
  374. \item[SYS\_EMSGSIZE] The message cannot be sent atomically.
  375. \item[SYS\_EWOULDBLOCK] The requested operation would block the process.
  376. \item[SYS\_ENOBUFS] The system doesn't have enough free buffers available.
  377. \end{description}
  378. \SeeAlso
  379. \seef{Send}
  380. \end{function}
  381. \begin{function}{Send}
  382. \Declaration
  383. Function Send (Sock:Longint;Var Addr;AddrLen,Flags:Longint) : Longint;
  384. \Description
  385. \var{Send} sends \var{AddrLen} bytes starting from address \var{Addr}
  386. to socket \var{Sock}. \var{Sock} must be in a connected state.
  387. The function returns the number of bytes sent, or -1 if a detectable
  388. error occurred.
  389. \var{Flags} can be one of the following:
  390. \begin{description}
  391. \item [1] : Process out-of band data.
  392. \item [4] : Bypass routing, use a direct interface.
  393. \end{description}
  394. \Errors
  395. Errors are reported in \var{SocketError}, and include the following:
  396. \begin{description}
  397. \item[SYS\_EBADF] The socket descriptor is invalid.
  398. \item[SYS\_ENOTSOCK] The descriptor is not a socket.
  399. \item[SYS\_EFAULT] The address is outside your address space.
  400. \item[SYS\_EMSGSIZE] The message cannot be sent atomically.
  401. \item[SYS\_EWOULDBLOCK] The requested operation would block the process.
  402. \item[SYS\_ENOBUFS] The system doesn't have enough free buffers available.
  403. \end{description}
  404. \SeeAlso
  405. \seef{Recv}, \seem{send}{2}
  406. \end{function}
  407. \begin{function}{SetSocketOptions}
  408. \Declaration
  409. Function SetSocketOptions (Sock,Level,OptName:Longint;Var OptVal;optlen:longint) : Longint;
  410. \Description
  411. \var{SetSocketOptions} sets the connection options for socket \var{Sock}.
  412. The socket may be manipulated at different levels, indicated by \var{Level},
  413. which can be one of the following:
  414. \begin{description}
  415. \item[SOL\_SOCKET] To manipulate the socket itself.
  416. \item[XXX] set \var{Level} to \var{XXX}, the protocol number of the protocol
  417. which should interprete the option.
  418. \end{description}
  419. For more information on this call, refer to the unix manual page \seem{setsockopt}{2}.
  420. \Errors
  421. Errors are reported in \var{SocketError}, and include the following:
  422. \begin{description}
  423. \item[SYS\_EBADF] The socket descriptor is invalid.
  424. \item[SYS\_ENOTSOCK] The descriptor is not a socket.
  425. \item[SYS\_EFAULT] \var{OptVal} points outside your address space.
  426. \end{description}
  427. \SeeAlso
  428. \seef{GetSocketOptions}
  429. \end{function}
  430. \begin{function}{Shutdown}
  431. \Declaration
  432. Function Shutdown (Sock:Longint;How:Longint) : Longint;
  433. \Description
  434. \var{ShutDown} closes one end of a full duplex socket connection, described
  435. by \var{Sock}. \var{How} determines how the connection will be shut down,
  436. and can be one of the following:
  437. \begin{description}
  438. \item[0] : Further receives are disallowed.
  439. \item[1] : Further sends are disallowed.
  440. \item[2] : Sending nor receiving are allowed.
  441. \end{description}
  442. On succes, the function returns 0, on error -1 is returned.
  443. \Errors
  444. \var{SocketError} is used to report errors, and includes the following:
  445. \begin{description}
  446. \item[SYS\_EBADF] The socket descriptor is invalid.
  447. \item[SYS\_ENOTCONN] The socket isn't connected.
  448. \item[SYS\_ENOTSOCK] The descriptor is not a socket.
  449. \end{description}
  450. \SeeAlso
  451. \seef{Socket}, \seef{Connect}
  452. \end{function}
  453. \begin{procedure}{Sock2File}
  454. \Declaration
  455. Procedure Sock2File (Sock:Longint;Var SockIn,SockOut:File);
  456. \Description
  457. \var{Sock2File} transforms a socket \var{Sock} into 2 Pascal file
  458. descriptors of type \var{File}, one for reading from the socket
  459. (\var{SockIn}), one for writing to the socket (\var{SockOut}).
  460. \Errors
  461. None.
  462. \SeeAlso
  463. \seef{Socket}, \seep{Sock2Text}
  464. \end{procedure}
  465. \begin{procedure}{Sock2Text}
  466. \Declaration
  467. Procedure Sock2Text (Sock:Longint;Var SockIn,SockOut: Text);
  468. \Description
  469. \var{Sock2Text} transforms a socket \var{Sock} into 2 Pascal file
  470. descriptors of type \var{Text}, one for reading from the socket
  471. (\var{SockIn}), one for writing to the socket (\var{SockOut}).
  472. \Errors
  473. None.
  474. \SeeAlso
  475. \seef{Socket}, \seep{Sock2File}
  476. \end{procedure}
  477. \begin{function}{Socket}
  478. \Declaration
  479. Function Socket (Domain,SocketType,Protocol:Longint) : Longint;
  480. \Description
  481. \var{Socket} creates a new socket in domain \var{Domain}, from type
  482. \var{SocketType} using protocol \var{Protocol}.
  483. The Domain, Socket type and Protocol can be specified using predefined
  484. constants (see the section on constants for available constants)
  485. If succesfull, the function returns a socket descriptor, which can be passed
  486. to a subsequent \seef{Bind} call. If unsuccesfull, the function returns -1.
  487. \Errors
  488. Errors are returned in \var{SocketError}, and include the follwing:
  489. \begin{description}
  490. \item[SYS\_EPROTONOSUPPORT]
  491. The protocol type or the specified protocol is not
  492. supported within this domain.
  493. \item[SYS\_EMFILE]
  494. The per-process descriptor table is full.
  495. \item[SYS\_ENFILE]
  496. The system file table is full.
  497. \item[SYS\_EACCESS]
  498. Permission to create a socket of the specified
  499. type and/or protocol is denied.
  500. \item[SYS\_ENOBUFS]
  501. Insufficient buffer space is available. The
  502. socket cannot be created until sufficient
  503. resources are freed.
  504. \end{description}
  505. \SeeAlso
  506. \seef{SocketPair}, \seem{socket}{2}
  507. \end{function}
  508. for an example, see \seef{Accept}.
  509. \begin{function}{SocketPair}
  510. \Declaration
  511. Function SocketPair (Domain,SocketType,Protocol:Longint;var Pair:TSockArray) : Longint;
  512. \Description
  513. \var{SocketPair} creates 2 sockets in domain \var{Domain}, from type
  514. \var{SocketType} and using protocol \var{Protocol}.
  515. The pair is returned in \var{Pair}, and they are indistinguishable.
  516. The function returns -1 upon error and 0 upon success.
  517. \Errors
  518. Errors are reported in \var{SocketError}, and are the same as in \seef{Socket}
  519. \SeeAlso
  520. \seep{Str2UnixSockAddr}
  521. \end{function}
  522. \begin{procedure}{Str2UnixSockAddr}
  523. \Declaration
  524. Procedure Str2UnixSockAddr(const addr:string;var t:TUnixSockAddr;var len:longint)
  525. \Description
  526. \var{Str2UnixSockAddr} transforms a Unix socket address in a string to a
  527. \var{TUnixSockAddr} structure which can be passed to the \seef{Bind} call.
  528. \Errors
  529. None.
  530. \SeeAlso
  531. \seef{Socket}, \seef{Bind}
  532. \end{procedure}