Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow sock_recv to cope with short reads #7

Merged
merged 1 commit into from

3 participants

@horms

I have observed on Linux that without this change reads are limited to the MTU of the interface used for TCP communication, module any affects of LRO.

@horms horms Allow sock_recv to cope with short reads
I have observed on Linux that without this change reads are limited to the MTU
of the interface used for TCP communication, module any affects of LRO.
d06a5b9
@kpntrifork kpntrifork merged commit 75e14c6 into trifork:master
@kpntrifork
Collaborator

Nice find, thanks a lot :+1:

@krestenkrab
Owner

The same fix should probably also be applied to write/send.

@horms

Yes, I suspect so, though I have not observed a problem on the write side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 27, 2012
  1. @horms

    Allow sock_recv to cope with short reads

    horms authored
    I have observed on Linux that without this change reads are limited to the MTU
    of the interface used for TCP communication, module any affects of LRO.
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 1 deletion.
  1. +19 −1 src/riack_sock.c
View
20 src/riack_sock.c
@@ -19,6 +19,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <errno.h>
#ifdef WIN32
#include <winsock2.h>
@@ -134,7 +135,24 @@ int sock_set_timeouts(int sockfd, uint32_t recv_timeout, uint32_t send_timeout)
}
int sock_recv(int sockfd, uint8_t* buff, int len)
{
- return recv(sockfd, (char*)buff, len, 0);
+ int offset = 0;
+
+ while (offset < len) {
+ int recieved;
+ recieved = recv(sockfd, (char*)buff + offset, len - offset, 0);
+ if (recieved < 0) {
+ if (errno == EINTR) {
+ /* Try again */
+ continue;
+ }
+ return recieved;
+ }
+ if (recieved == 0) {
+ break;
+ }
+ offset += recieved;
+ }
+ return offset;
}
int sock_send(int sockfd, uint8_t* data, int len)
Something went wrong with that request. Please try again.