sockets.tex 20 KB

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