SSL_write.pod 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. =pod
  2. =head1 NAME
  3. SSL_write_ex, SSL_write - write bytes to a TLS/SSL connection
  4. =head1 SYNOPSIS
  5. #include <openssl/ssl.h>
  6. int SSL_write_ex(SSL *s, const void *buf, size_t num, size_t *written);
  7. int SSL_write(SSL *ssl, const void *buf, int num);
  8. =head1 DESCRIPTION
  9. SSL_write_ex() and SSL_write() write B<num> bytes from the buffer B<buf> into
  10. the specified B<ssl> connection. On success SSL_write_ex() will store the number
  11. of bytes written in B<*written>.
  12. =head1 NOTES
  13. In the paragraphs below a "write function" is defined as one of either
  14. SSL_write_ex(), or SSL_write().
  15. If necessary, a write function will negotiate a TLS/SSL session, if not already
  16. explicitly performed by L<SSL_connect(3)> or L<SSL_accept(3)>. If the peer
  17. requests a re-negotiation, it will be performed transparently during
  18. the write function operation. The behaviour of the write functions depends on the
  19. underlying BIO.
  20. For the transparent negotiation to succeed, the B<ssl> must have been
  21. initialized to client or server mode. This is being done by calling
  22. L<SSL_set_connect_state(3)> or SSL_set_accept_state()
  23. before the first call to a write function.
  24. If the underlying BIO is B<blocking>, the write functions will only return, once
  25. the write operation has been finished or an error occurred.
  26. If the underlying BIO is B<non-blocking> the write functions will also return
  27. when the underlying BIO could not satisfy the needs of the function to continue
  28. the operation. In this case a call to L<SSL_get_error(3)> with the
  29. return value of the write function will yield B<SSL_ERROR_WANT_READ>
  30. or B<SSL_ERROR_WANT_WRITE>. As at any time a re-negotiation is possible, a
  31. call to a write function can also cause read operations! The calling process
  32. then must repeat the call after taking appropriate action to satisfy the needs
  33. of the write function. The action depends on the underlying BIO. When using a
  34. non-blocking socket, nothing is to be done, but select() can be used to check
  35. for the required condition. When using a buffering BIO, like a BIO pair, data
  36. must be written into or retrieved out of the BIO before being able to continue.
  37. The write functions will only return with success when the complete contents of
  38. B<buf> of length B<num> has been written. This default behaviour can be changed
  39. with the SSL_MODE_ENABLE_PARTIAL_WRITE option of L<SSL_CTX_set_mode(3)>. When
  40. this flag is set the write functions will also return with success when a
  41. partial write has been successfully completed. In this case the write function
  42. operation is considered completed. The bytes are sent and a new write call with
  43. a new buffer (with the already sent bytes removed) must be started. A partial
  44. write is performed with the size of a message block, which is 16kB.
  45. =head1 WARNING
  46. When a write function call has to be repeated because L<SSL_get_error(3)>
  47. returned B<SSL_ERROR_WANT_READ> or B<SSL_ERROR_WANT_WRITE>, it must be repeated
  48. with the same arguments.
  49. The data that was passed might have been partially processed.
  50. When B<SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER> was set using L<SSL_CTX_set_mode(3)>
  51. the pointer can be different, but the data and length should still be the same.
  52. You should not call SSL_write() with num=0, it will return an error.
  53. SSL_write_ex() can be called with num=0, but will not send application data to
  54. the peer.
  55. =head1 RETURN VALUES
  56. SSL_write_ex() will return 1 for success or 0 for failure. Success means that
  57. all requested application data bytes have been written to the SSL connection or,
  58. if SSL_MODE_ENABLE_PARTIAL_WRITE is in use, at least 1 application data byte has
  59. been written to the SSL connection. Failure means that not all the requested
  60. bytes have been written yet (if SSL_MODE_ENABLE_PARTIAL_WRITE is not in use) or
  61. no bytes could be written to the SSL connection (if
  62. SSL_MODE_ENABLE_PARTIAL_WRITE is in use). Failures can be retryable (e.g. the
  63. network write buffer has temporarily filled up) or non-retryable (e.g. a fatal
  64. network error). In the event of a failure call L<SSL_get_error(3)> to find out
  65. the reason which indicates whether the call is retryable or not.
  66. For SSL_write() the following return values can occur:
  67. =over 4
  68. =item E<gt> 0
  69. The write operation was successful, the return value is the number of
  70. bytes actually written to the TLS/SSL connection.
  71. =item Z<><= 0
  72. The write operation was not successful, because either the connection was
  73. closed, an error occurred or action must be taken by the calling process.
  74. Call SSL_get_error() with the return value B<ret> to find out the reason.
  75. Old documentation indicated a difference between 0 and -1, and that -1 was
  76. retryable.
  77. You should instead call SSL_get_error() to find out if it's retryable.
  78. =back
  79. =head1 HISTORY
  80. SSL_write_ex() was added in OpenSSL 1.1.1.
  81. =head1 SEE ALSO
  82. L<SSL_get_error(3)>, L<SSL_read_ex(3)>, L<SSL_read(3)>
  83. L<SSL_CTX_set_mode(3)>, L<SSL_CTX_new(3)>,
  84. L<SSL_connect(3)>, L<SSL_accept(3)>
  85. L<SSL_set_connect_state(3)>,
  86. L<ssl(7)>, L<bio(7)>
  87. =head1 COPYRIGHT
  88. Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
  89. Licensed under the OpenSSL license (the "License"). You may not use
  90. this file except in compliance with the License. You can obtain a copy
  91. in the file LICENSE in the source distribution or at
  92. L<https://www.openssl.org/source/license.html>.
  93. =cut