sockets.tex 20 KB

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