Who can explain how to use WSARecv? I see that there you need to pass a previously prepared buffer for reading, and it annoys me every time. Is there an option where I can only get the size of the incoming data? And I will read it myself.

Periodically looking for easier ways to work with sockets. But unfortunately I’m stubbornly staying on the standard POSIX: socket(), listen(), select() version POSIX: socket(), listen(), select() ...

Are there simple and smart options for working with sockets for Linux and Windows? Consisting of receiving messages about data in a socket and the ability to write to it. I think to read about working with sockets through signals on Linux. And as an option to rewrite the TCP stack, unfortunately this code will require administrator rights.

  • Unclear. And I will read it myself. Where do you read from? With a piece of paper in accordance with rfc1149? Or from where? And as an option to rewrite the TCP stack And solder the network adapter scheme? PS: the option "read it yourself" and "rewrite the TCP stack" is quite possible when creating devices on microcontrollers ... - alexlz
  • @mikelsv, you first define your true orientation (WSARecv or linux). In general, I do not advise contacting signals. If you need something flexible, look at fcntl / ioctl for non-blocking IO along with poll () or epoll () (but this is pure Linux). Maybe one poll () (epoll ()) will be enough. - Will you rewrite the TCP stack right after tftp is completed? (by the way, how is it moving? not cold?) - avp
  • one
    I once wrote a stack on UDP and it even worked. In tcp it should not be particularly difficult. But this idea is more fun. I have an orientation immediately on Windows and on Linux. Now I am trying to attach a tftp server to an android. While rests. And, no, everything finally worked. "Received 2625504 bytes in 17.8 seconds" via wifi. - mikelsv
  • @ mikelsv, and have you already received the file in the server? - avp
  • one
    @avp, repaired svn: //svn.loglist.org: 2402 / usr / svn / opensource, now swinging. I would say that the functions on the C to work with tftp should be written when there is a need for them. As soon as I get a device that supports only C, I'll write right away. And before that I have nowhere to use this code. I do not see its practical value. If you look, the main loop in the tftp client, in which all the work happens, is practically written in the style of C. If you separate it, you get the file upload / download function. - mikelsv

1 answer 1

Who can explain how to use WSARecv? I see that there you need to pass a prepared buffer for reading

You can allocate a buffer once and reuse it. Usually they do.

Is there an option where I can only get the size of the incoming data? And I will read it myself.

Bad way. Not only will you need two requests instead of one, there’s also another problem. Meanwhile, as requested size and went to read it, new data can come running. And WSARecv (as well as recv) reads how many can and the number returns.

Are there simple and smart options for working with sockets for Linux and Windows? Consisting of receiving messages about data in a socket and the ability to write to it.

Yes, for example epoll for Linux and I / O Completion Ports (Windows) . BSD often uses kqueue . But usually use ready-made libraries, such as libev , libevent . And of course boost :: asio and ACE .

And as an option to rewrite the TCP stack, unfortunately this code will require administrator rights.

TCP stack is not an easy task. Do you think you can write better?

Read more here .

update: Find out how many bytes you can read right now from the socket, but you can. To do this, use this call

 ioctlsocket(socket, FIONREAD, &toRead) 

But about the details - refer to the appropriate guide .

  • Hmm I read articles. The question is shifting towards the provision of 10k connections. Following the results, I'm thinking about using WSARecv and see what comes of it. About TCP: It is enough to write a TCP stack no worse. But it will work much better, due to the availability of a pile of information. But probably slower. Perhaps this can be done as a research topic. - mikelsv
  • In which of the cores will you change TCP? - avp
  • @avp, why in the cores? Each program has its own TCP stack! - mikelsv
  • And your ethernet. Or at least a wi-fi module. Implement rfc1149 (and heirs) on the android (just do not forget about safety precautions so that the package carriers do not stain the package). - alexlz
  • But what about your byte, for 10 and a half bits? :) - KoVadim