Skip to content
Snippets Groups Projects
Commit 6bef099e authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Fix nasty websocket stack bug

parent abb69a7c
No related branches found
No related tags found
1 merge request!316Resolves #343 GUI and Frame Refactor
Pipeline #28416 passed
...@@ -664,6 +664,8 @@ void Peer::_connected() { ...@@ -664,6 +664,8 @@ void Peer::_connected() {
int Peer::_send() { int Peer::_send() {
if (sock_ == INVALID_SOCKET) return -1; if (sock_ == INVALID_SOCKET) return -1;
int c=0;
// Are we using a websocket? // Are we using a websocket?
if (scheme_ == ftl::URI::SCHEME_WS) { if (scheme_ == ftl::URI::SCHEME_WS) {
// Create a websocket header as well. // Create a websocket header as well.
...@@ -690,8 +692,25 @@ int Peer::_send() { ...@@ -690,8 +692,25 @@ int Peer::_send() {
// Patch the first io vector to be ws header // Patch the first io vector to be ws header
const_cast<iovec*>(&sendvec[0])->iov_base = buf; const_cast<iovec*>(&sendvec[0])->iov_base = buf;
const_cast<iovec*>(&sendvec[0])->iov_len = rc; const_cast<iovec*>(&sendvec[0])->iov_len = rc;
#ifdef WIN32
auto send_vec = send_buf_.vector();
auto send_size = send_buf_.vector_size();
vector<WSABUF> wsabuf(send_size);
for (int i = 0; i < send_size; i++) {
wsabuf[i].len = (ULONG)send_vec[i].iov_len;
wsabuf[i].buf = (char*)send_vec[i].iov_base;
//c += ftl::net::internal::send(sock_, (char*)send_vec[i].iov_base, (int)send_vec[i].iov_len, 0);
} }
DWORD bytessent;
c = WSASend(sock_, wsabuf.data(), static_cast<DWORD>(send_size), (LPDWORD)&bytessent, 0, NULL, NULL);
#else
c = ftl::net::internal::writev(sock_, send_buf_.vector(), (int)send_buf_.vector_size());
#endif
} else {
#ifdef WIN32 #ifdef WIN32
auto send_vec = send_buf_.vector(); auto send_vec = send_buf_.vector();
auto send_size = send_buf_.vector_size(); auto send_size = send_buf_.vector_size();
...@@ -704,10 +723,11 @@ int Peer::_send() { ...@@ -704,10 +723,11 @@ int Peer::_send() {
} }
DWORD bytessent; DWORD bytessent;
int c = WSASend(sock_, wsabuf.data(), static_cast<DWORD>(send_size), (LPDWORD)&bytessent, 0, NULL, NULL); c = WSASend(sock_, wsabuf.data(), static_cast<DWORD>(send_size), (LPDWORD)&bytessent, 0, NULL, NULL);
#else #else
int c = ftl::net::internal::writev(sock_, send_buf_.vector(), (int)send_buf_.vector_size()); c = ftl::net::internal::writev(sock_, send_buf_.vector(), (int)send_buf_.vector_size());
#endif #endif
}
send_buf_.clear(); send_buf_.clear();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment