| 36 | } |
| 37 | |
| 38 | ssize_t WriteBufferFromPocoSocket::socketSendBytesImpl(const char * ptr, size_t size) |
| 39 | { |
| 40 | ssize_t res = 0; |
| 41 | |
| 42 | /// If async_callback is specified, set socket to non-blocking mode |
| 43 | /// and try to write data to it, if socket is not ready for writing, |
| 44 | /// run async_callback and try again later. |
| 45 | /// It is expected that file descriptor may be polled externally. |
| 46 | /// Note that send timeout is not checked here. External code should check it while polling. |
| 47 | if (async_callback) |
| 48 | { |
| 49 | socket.setBlocking(false); |
| 50 | /// Set socket to blocking mode at the end. |
| 51 | SCOPE_EXIT_SAFE(socket.setBlocking(true)); |
| 52 | bool secure = socket.secure(); |
| 53 | res = socket.impl()->sendBytes(ptr, static_cast<int>(size)); |
| 54 | |
| 55 | /// Check EAGAIN and ERR_SSL_WANT_WRITE/ERR_SSL_WANT_READ for secure socket (writing to secure socket can read too). |
| 56 | while (res < 0 && (errno == EAGAIN || (secure && (checkSSLWantRead(res) || checkSSLWantWrite(res))))) |
| 57 | { |
| 58 | /// In case of ERR_SSL_WANT_READ we should wait for socket to be ready for reading, otherwise - for writing. |
| 59 | if (secure && checkSSLWantRead(res)) |
| 60 | async_callback(socket.impl()->sockfd(), socket.getReceiveTimeout(), AsyncEventTimeoutType::RECEIVE, socket_description, AsyncTaskExecutor::Event::READ | AsyncTaskExecutor::Event::ERROR); |
| 61 | else |
| 62 | async_callback(socket.impl()->sockfd(), socket.getSendTimeout(), AsyncEventTimeoutType::SEND, socket_description, AsyncTaskExecutor::Event::WRITE | AsyncTaskExecutor::Event::ERROR); |
| 63 | |
| 64 | /// Try to write again. |
| 65 | res = socket.impl()->sendBytes(ptr, static_cast<int>(size)); |
| 66 | } |
| 67 | } |
| 68 | else |
| 69 | { |
| 70 | res = socket.impl()->sendBytes(ptr, static_cast<int>(size)); |
| 71 | } |
| 72 | |
| 73 | return res; |
| 74 | } |
| 75 | |
| 76 | void WriteBufferFromPocoSocket::socketSendBytes(const char * ptr, size_t size) |
| 77 | { |
nothing calls this directly
no test coverage detected