Questions tagged [select-function]

This tag is for questions regarding select() system function. This function is used to avoid busy waiting. For such questions use this tag rather than 'select' tag which is too broad.

select() is an important system call used by C and C++ programs and libraries that avoids busy waiting for network activity and other I/O to complete.
For questions regarding select() function use this tag instead of which is too broad.

51 questions
13
votes
5 answers

C, socket programming: Connecting multiple clients to server using select()

I'm trying to make a server that can be connected to by multiple clients. Here's my code so far: Client: int main(int argc, char **argv) { struct sockaddr_in servaddr; int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock == -1)…
ragnaroh
  • 344
  • 2
  • 3
  • 12
10
votes
3 answers

How to use select() to read input from keyboard in C

I am trying to use select() to read keyboard input and I got stuck in that I do not know how to read from keyboard and use a file descriptor to do so. I've been told to use STDIN and STDIN_FILENO to approach this problem but I am still confused. How…
drum
  • 5,416
  • 7
  • 57
  • 91
8
votes
2 answers

Read signaled by select(), but recv() returns no data and signal EAGAIN on non-blocking sockets

I have got signaled socket for read from select(), but then no data arrived by recv call(), instead it returns -1 with errno==EAGAIN. I can grant that no other thread touch the socket. I think that this behavior is not correct. If an subsequent…
Zdenal
  • 81
  • 1
  • 2
4
votes
2 answers

Using sleep and select with signals

I want to use the select() function to wait for 1 second, as my program uses signals to control stuff, so sleep() would return prematurely. The weird thing is that when using select() it also returns prematurely. I am calling select like this …
Sergio Campamá
  • 746
  • 1
  • 7
  • 14
4
votes
1 answer

Why does the following prints 'Resource temporarily unavailable'?

Why does the following code print ‘read(): Resource temporarily unavailable’ 80% of the time? That is the EAGAIN code, which is the same as WOULD BLOCK which means there is no data waiting to be read, but select is returning 1 saying there is data…
user10060
  • 43
  • 1
  • 3
4
votes
1 answer

Knowing which file-descriptors are ready after select() call in C

I'm new to socket programming and I've been introduced to the select() system call. My question is, lets say I'm writing a server in C (which I am attempting to do) and I want to use the select() call in my implementation for practice. I'm trying to…
thanos
  • 3,203
  • 4
  • 18
  • 27
4
votes
2 answers

Impact of using select with blocking and non-blocking sockets

How will my program differ in behavior if I use non-blocking sockets with a select() call as opposed to using blocking sockets with a select() call?
DaTaBomB
  • 623
  • 3
  • 11
  • 23
3
votes
2 answers

non blocking socket select returns 1 after connect

First of all I would like to say that this is another problem than this one: Similar but not the same My code looks like this: struct addrinfo hints, *res; struct sockaddr* serveraddr; memset(&hints, 0, sizeof(hints)); hints.ai_family =…
Kamil_H
  • 501
  • 1
  • 5
  • 12
3
votes
2 answers

Select (Linux) function always returns 0

Select function in my case always returns zero, which is timeout and this is happening continuosly so my CPU usage also going upto 98 % for my process. I have also tried to set NULL instead of seting some timeout value , still it returns zero. I…
3
votes
1 answer

Using select() system call for listening on stdin and the server

I want to use select system call to multiplex STDIN and SOCKFD (connected to a server) such that I must be listening to both STDIN and SOCKFD and depending upon where the data is available for read I must proceed further. Note: #define STDIN 0 This…
Mir
  • 670
  • 4
  • 9
  • 20
3
votes
1 answer

socket programming with select

I have two nodes communicating with a socket. Each node has a read thread and a write thread to communicate with the other. Given below is the code for the read thread. The communication works fine between the two nodes with that code. But I am…
Romonov
  • 8,145
  • 14
  • 43
  • 55
3
votes
2 answers

select failing with C program but not shell

I have a parent and child process, and the parent can read output from the child and send to the input of the child. So far, everything has been working fine with shell scripts, testing commands which input and output data. I just tested with a…
Gary
  • 926
  • 3
  • 12
  • 24
3
votes
2 answers

C - filling TCP socket send buffer

I'm trying to write an experimental client / server program to prove whether the write fails or blocks when the send buffer is full. Basically, I have an infinite loop on the sender program where I use select() to check if I can write on the buffer…
selfm
  • 101
  • 1
  • 9
3
votes
2 answers

Is there a Windows equivalent for eventfd?

I am writing a cross-platform library which emulates sockets behaviour, having additional functionality in the between (App->mylib->sockets). I want it to be the most transparent possible for the programmer, so primitives like select and poll must…
Leaurus
  • 376
  • 3
  • 13
2
votes
1 answer

linux: stdin causes select to return when I don't want it to

I have a problem with select returning when there is something on stdin, even though I don't want it to. For example here is a code that is meant to wait for data on a socket for a certain amount of time, however if there is data on stdin, select…
myforwik
  • 119
  • 2
  • 6
1
2 3 4