[Rd] Question on non-blocking socket
Tomas Kalibera
tom@@@k@||ber@ @end|ng |rom gm@||@com
Wed Feb 15 14:38:08 CET 2023
On 2/15/23 01:24, Ben Engbers wrote:
> Hi,
>
> December 27, 2021 I started a thread asking for help troubleshooting
> non-blocking sockets.
> While developing the RBaseX client, I had issues with the
> authentication process. It eventually turned out that a short break
> had to be inserted in this process between sending the credentials to
> the server and requesting the status. Tomas Kalibera put me on the
> right track by drawing my attention to the 'socketSelect' function. I
> don't know exactly the purpose of this function is (the function
> itself is documented, but I can't find any information for which
> situations this function should be called.) but it sufficed to call
> this function once between sending and requesting.
>
> I have two questions.
> The first is where I can find R documentation on proper use of
> non-blocking sockets and on the proper use of the socketSelect function?
In addition to the demos I sent to you in that 2021 thread on
R-pkg-devel, you could also have a look at how it is used in R itself,
in the parallel package, in snowSOCK.R, to set up the snow cluster in
parallel. Some hints may be also found in the blog post
https://blog.r-project.org/2020/03/17/socket-connections-update/. But,
in principle, R API is just a thin layer on top of what the OS provides,
so general literature and tutorials on sockets should help, there should
be even textbooks used at CS universities in networking classes.
Basically select() can tell you when data is ready (on input), when the
socket interface is able to accept more data (on output) or when there
is an incoming connection. In practice, you should not need any delays
to be inserted in your program to make it work - if that is needed, it
means that is an error in it (a race condition). If the program is
polling (checking in a loop whether something has already happened, and
then sleeping for a short while), the duration of the sleep may indeed
influence latency, but should not affect correctness - if it does, there
is an error.
> The second question is more focused on using non-blocking sockets in
> general. Is it allowed to execute a read and a receive command
> immediately after each other or must a short waiting loop be built in.
> I'm asking this because I'm running into the same problems in a C++
> project as I did with RBaseX.
No, in general there is no need to insert any delays between reads and
writes, they can actually happen concurrently. But these are general
networking questions, not the topic of this list.
Best
Tomas
>
> Ben Engbers
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
More information about the R-devel
mailing list