nn_connect.adoc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. nn_connect(3)
  2. =============
  3. NAME
  4. ----
  5. nn_connect - add a remote endpoint to the socket
  6. SYNOPSIS
  7. --------
  8. *#include <nanomsg/nn.h>*
  9. *int nn_connect (int 's', const char '*addr');*
  10. DESCRIPTION
  11. -----------
  12. Adds a remote endpoint to the socket 's'. The library would then try to connect
  13. to the specified remote endpoint.
  14. The 'addr' argument consists of two parts as follows: 'transport'`://`'address'.
  15. The 'transport' specifies the underlying transport protocol to use. The meaning
  16. of the 'address' part is specific to the underlying transport protocol.
  17. For the list of available transport protocols check the list on
  18. <<nanomsg#,nanomsg(7)>> manual page.
  19. Maximum length of the 'addr' parameter is specified by _NN_SOCKADDR_MAX_
  20. defined in '<nanomsg/nn.h>' header file.
  21. Note that nn_connect and <<nn_bind#,nn_bind(3)>> may be called multiple times
  22. on the same socket thus allowing the socket to communicate with multiple
  23. heterogeneous endpoints.
  24. NOTE
  25. ----
  26. Unlike with traditional BSD sockets, this function operates asynchronously,
  27. and returns to the caller before the operation is complete.
  28. As a result, attempts to send data or receive data on the socket may not
  29. succeed until the underlying transport actually establishes the connection.
  30. Further, the connection may be lost, without any notification to the caller.
  31. The library will attempt to reconnect automatically in such an event.
  32. RETURN VALUE
  33. ------------
  34. If the function succeeds positive endpoint ID is returned. Endpoint ID can be
  35. later used to remove the endpoint from the socket via <<nn_shutdown#,nn_shutdown(3)>>
  36. function.
  37. If the function fails negative value is returned and 'errno' is set to to one of
  38. the values defined below.
  39. ERRORS
  40. ------
  41. *EBADF*::
  42. The provided socket is invalid.
  43. *EMFILE*::
  44. Maximum number of active endpoints was reached.
  45. *EINVAL*::
  46. The syntax of the supplied address is invalid.
  47. *ENAMETOOLONG*::
  48. The supplied address is too long.
  49. *EPROTONOSUPPORT*::
  50. The requested transport protocol is not supported.
  51. *ENODEV*::
  52. Address specifies a nonexistent interface.
  53. *ETERM*::
  54. The library is terminating.
  55. EXAMPLE
  56. -------
  57. ----
  58. s = nn_socket (AF_SP, NN_PUB);
  59. eid1 = nn_connect (s, "ipc:///tmp/test.ipc");
  60. eid2 = nn_connect (s, "tcp://server001:5560");
  61. ----
  62. SEE ALSO
  63. --------
  64. <<nn_inproc#,nn_inproc(7)>>
  65. <<nn_ipc#,nn_ipc(7)>>
  66. <<nn_tcp#,nn_tcp(7)>>
  67. <<nn_socket#,nn_socket(3)>>
  68. <<nn_bind#,nn_bind(3)>>
  69. <<nn_shutdown#,nn_shutdown(3)>>
  70. <<nanomsg#,nanomsg(7)>>
  71. AUTHORS
  72. -------
  73. link:mailto:sustrik@250bpm.com[Martin Sustrik]
  74. link:mailto:garrett@damore.org[Garrett D'Amore]