Skip to content

Commit c1e57a0

Browse files
authored
Add support for sending data streams via callback (TcpConnection::sendStream()) (#196)
1 parent f308457 commit c1e57a0

File tree

7 files changed

+457
-58
lines changed

7 files changed

+457
-58
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ if(HAVE_C-ARES)
148148
set(private_headers
149149
${private_headers}
150150
trantor/net/inner/AresResolver.h)
151+
if(APPLE)
152+
target_link_libraries(${PROJECT_NAME} PRIVATE resolv)
153+
endif()
151154
else()
152155
set(TRANTOR_SOURCES
153156
${TRANTOR_SOURCES}

trantor/net/TcpConnection.h

100755100644
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ class TRANTOR_EXPORT TcpConnection
7676
virtual void sendFile(const wchar_t *fileName,
7777
size_t offset = 0,
7878
size_t length = 0) = 0;
79+
/**
80+
* @brief Send a stream to the peer.
81+
*
82+
* @param callback function to retrieve the stream data (stream ends when a
83+
* zero size is returned) the callback will be called with nullptr when the
84+
* send is finished/interrupted, so that it cleans up any internal data (ex:
85+
* close file).
86+
* @warning The buffer size should be >= 10 to allow http chunked-encoding
87+
* data stream
88+
*/
89+
virtual void sendStream(std::function<std::size_t(char *, std::size_t)>
90+
callback) = 0; // (buffer, buffer size) -> size
91+
// of data put in buffer
7992

8093
/**
8194
* @brief Get the local address of the connection.

trantor/net/inner/Socket.cc

100644100755
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,11 @@ int Socket::getSocketError()
228228

229229
if (::getsockopt(sockFd_, SOL_SOCKET, SO_ERROR, &optval, &optlen) < 0)
230230
{
231+
#ifdef _WIN32
232+
return ::WSAGetLastError();
233+
#else
231234
return errno;
235+
#endif
232236
}
233237
else
234238
{

0 commit comments

Comments
 (0)