Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCP socket stream #29775

Closed
liang8057 opened this issue Nov 4, 2020 · 4 comments
Closed

TCP socket stream #29775

liang8057 opened this issue Nov 4, 2020 · 4 comments
Labels

Comments

@liang8057
Copy link

Describe the bug
I set up a client socket to communicate with the remote server, and the server send five 1 byte packets.
I want to recv 5 bytes at a time, but there is no way. I need to call recv 5 times to receive the packets.

To Reproduce
struct sockaddr_in info;
int sock, ret;
char buf[100];

sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
memset(&info, 0, sizeof(info));
info.sin_family = PF_INET;

info.sin_addr.s_addr = inet_addr("192.168.127.5");
info.sin_port = htons(8700);

connect(sock, (struct sockaddr *)&info, sizeof(info));

k_sleep(K_SECONDS(10));

ret = recv(sock, buf, 5, 0);
printf("ret %d\n", ret);

The server transmits the five packets in 10 seconds, and then I start to receive.
But I found that I had to call recv 5 times to receive all the packets.

Environment (please complete the following information):

  • OS: Zephyr2.4
  • Toolchain: zephyr-sdk-0.11.2
@liang8057 liang8057 added the bug The issue is a bug, or the PR is fixing a bug label Nov 4, 2020
@jukkar
Copy link
Member

jukkar commented Nov 4, 2020

This is very typical in TCP, if the peer sends us things one byte a time then we receive each byte in separate TCP segment. We do not collect the packets anywhere in receive path so you will also receive things one byte a time. This is not a bug.

@jukkar jukkar added question and removed bug The issue is a bug, or the PR is fixing a bug labels Nov 4, 2020
@liang8057
Copy link
Author

But I tested on Linux under the same situation, and the result is that there is unnecessary to recv five times.

@jukkar
Copy link
Member

jukkar commented Nov 5, 2020

But I tested on Linux under the same situation, and the result is that there is unnecessary to recv five times.

Sure, but in Linux there is queueing in receive side which collects smaller packets into larger ones before giving them to the application. Zephyr does not do it currently because it requires memory and we try to limit the memory usage.

@github-actions
Copy link

github-actions bot commented Jan 5, 2021

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants