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

Improve peer unit test for windows

parent 5f10e939
No related branches found
No related tags found
No related merge requests found
Pipeline #29173 failed
......@@ -11,6 +11,7 @@ namespace ftl { namespace net { namespace internal {
#ifdef WIN32
int recv(SOCKET sd, char *buf, int n, int f);
int send(SOCKET sd, const char *v, int cnt, int flags);
int writev(SOCKET sd, LPWSABUF v, DWORD cnt, LPDWORD sent);
#else
ssize_t recv(int sd, void *buf, size_t n, int f);
ssize_t writev(int sd, const struct iovec *v, int cnt);
......@@ -19,6 +20,7 @@ namespace ftl { namespace net { namespace internal {
#ifdef WIN32
inline int recv(SOCKET sd, char *buf, int n, int f) { return ::recv(sd,buf,n,f); }
inline int send(SOCKET sd, const char *v, int cnt, int flags) { return ::send(sd,v,cnt,flags); }
inline int writev(SOCKET sd, LPWSABUF v, DWORD cnt, LPDWORD sent) { return ::WSASend(sd, v, cnt, sent, 0, NULL, NULL); }
#else
#if defined _DEBUG && DEBUG_NET
inline ssize_t recv(int sd, void *buf, size_t n, int f) {
......
......@@ -180,6 +180,7 @@ Peer::Peer(SOCKET s, Universe *u, Dispatcher *d) : sock_(s), can_reconnect_(fals
outgoing_ = false;
local_id_ = local_peer_ids__++;
#ifndef TEST_MOCKS
int flags =1;
if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const char *)&flags, sizeof(flags))) { LOG(ERROR) << "ERROR: setsocketopt(), TCP_NODELAY"; };
int a = static_cast<int>(u->getRecvBufferSize());
......@@ -190,6 +191,7 @@ Peer::Peer(SOCKET s, Universe *u, Dispatcher *d) : sock_(s), can_reconnect_(fals
if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, (const char *)&a, sizeof(int)) == -1) {
fprintf(stderr, "Error setting socket opts: %s\n", strerror(errno));
}
#endif
// Send the initiating handshake if valid
if (status_ == kConnecting) {
......@@ -699,7 +701,8 @@ int Peer::_send() {
}
DWORD bytessent;
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);
c = ftl::net::internal::writev(sock_, wsabuf.data(), static_cast<DWORD>(send_size), (LPDWORD)&bytessent);
#else
c = ftl::net::internal::writev(sock_, send_buf_.vector(), (int)send_buf_.vector_size());
#endif
......@@ -717,7 +720,8 @@ int Peer::_send() {
}
DWORD bytessent;
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);
c = ftl::net::internal::writev(sock_, wsabuf.data(), static_cast<DWORD>(send_size), (LPDWORD)&bytessent);
#else
c = ftl::net::internal::writev(sock_, send_buf_.vector(), (int)send_buf_.vector_size());
#endif
......
......@@ -85,11 +85,25 @@ ssize_t ftl::net::internal::recv(SOCKET sd, void *buf, size_t n, int f) {
}
#ifdef WIN32
int ftl::net::internal::send(SOCKET sd, const char *v, int cnt, int flags) {
/*int ftl::net::internal::send(SOCKET sd, const char *v, int cnt, int flags) {
int len = cnt;
// TODO(nick) merge multiple sends
fakedata[sd] = std::string(v, len);
return len;
}*/
int ftl::net::internal::writev(SOCKET sd, LPWSABUF v, DWORD cnt, LPDWORD sent) {
size_t len = 0; //v[0].iov_len+v[1].iov_len;
char buf[1000];
char *bufp = &buf[0];
for (auto i=0; i<cnt; i++) {
std::memcpy(bufp,v[i].buf,v[i].len);
len += v[i].len;
bufp += v[i].len;
}
fakedata[sd] = std::string(&buf[0], len);
return len;
}
#else
ssize_t ftl::net::internal::writev(int sd, const struct iovec *v, int cnt) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment