nn_send.adoc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. nn_send(3)
  2. ==========
  3. NAME
  4. ----
  5. nn_send - send a message
  6. SYNOPSIS
  7. --------
  8. *#include <nanomsg/nn.h>*
  9. *int nn_send (int 's', const void '*buf', size_t 'len', int 'flags');*
  10. DESCRIPTION
  11. -----------
  12. The function will send a message containing the data from buffer pointed to
  13. by 'buf' parameter to the socket 's'. The message will be 'len' bytes long.
  14. Alternatively, to send a buffer allocated by <<nn_allocmsg#,nn_allocmsg(3)>> function
  15. set the buf parameter to point to the pointer to the buffer and 'len' parameter
  16. to _NN_MSG_ constant. In this case a successful call to _nn_send_ will
  17. deallocate the buffer. Trying to deallocate it afterwards will result in
  18. undefined behaviour.
  19. Which of the peers the message will be sent to is determined by
  20. the particular socket type.
  21. The 'flags' argument is a combination of the flags defined below:
  22. *NN_DONTWAIT*::
  23. Specifies that the operation should be performed in non-blocking mode. If the
  24. message cannot be sent straight away, the function will fail with 'errno' set
  25. to EAGAIN.
  26. RETURN VALUE
  27. ------------
  28. If the function succeeds, the number of bytes in the message is returned.
  29. Otherwise, -1 is returned and 'errno' is set to to one of the
  30. values defined below.
  31. ERRORS
  32. ------
  33. *EFAULT*::
  34. 'buf' is NULL or 'len' is NN_MSG and the message pointer (pointed to by
  35. 'buf') is NULL.
  36. *EBADF*::
  37. The provided socket is invalid.
  38. *ENOTSUP*::
  39. The operation is not supported by this socket type.
  40. *EFSM*::
  41. The operation cannot be performed on this socket at the moment because the socket
  42. is not in the appropriate state. This error may occur with socket types that
  43. switch between several states.
  44. *EAGAIN*::
  45. Non-blocking mode was requested and the message cannot be sent at the moment.
  46. *EINTR*::
  47. The operation was interrupted by delivery of a signal before the message was
  48. sent.
  49. *ETIMEDOUT*::
  50. Individual socket types may define their own specific timeouts. If such timeout
  51. is hit, this error will be returned.
  52. *ETERM*::
  53. The library is terminating.
  54. EXAMPLE
  55. -------
  56. Using data directly:
  57. ----
  58. nbytes = nn_send (s, "ABC", 3, 0);
  59. assert (nbytes == 3);
  60. ----
  61. Using a pre-allocated message buffer:
  62. ----
  63. void *msg = nn_allocmsg(3, 0);
  64. strncpy(msg, "ABC", 3);
  65. nbytes = nn_send (s, &msg, NN_MSG, 0);
  66. assert (nbytes == 3);
  67. ----
  68. SEE ALSO
  69. --------
  70. <<nn_recv#,nn_recv(3)>>
  71. <<nn_sendmsg#,nn_sendmsg(3)>>
  72. <<nn_socket#,nn_socket(3)>>
  73. <<nanomsg#,nanomsg(7)>>
  74. AUTHORS
  75. -------
  76. link:mailto:sustrik@250bpm.com[Martin Sustrik]