2 llamadas consecutivas al sistema SELECT en el mismo fd (socket) una toma tiempo mientras que la segunda regresa inmediatamente, ¿por qué?

I have 2 'Seleccionar' calls one after other on same fd. both have diff fd_set, but both have only one fd int it and the same fd.(trying to read from the same socket)

the problem is second Select times out. I am trying to recreate the issue but cant, in my testing the second select goes through almost instantaneously, even with timeout=0.

I am confused. Does the Socket have data in Kernel Space due to which the second select goes through immediately.

preguntado el 08 de noviembre de 11 a las 14:11

Are you sure it's not a server problem? -

If the first select doesn't time out (i.e. data is available) and you do a second select without read, the second one should return immediately (because data is still available). That is normal. Is that what you are seeing? -

I am reading after both the selects... but still the second one returns immedeately..... -

1 Respuestas

Yes, the socket does have incoming data buffered in kernel space - that's what you'll get when you call read(), after the first select() returns to indicate that there is something available to read. If you haven't read it all yet, then of course another select() Regresará inmediatamente.

Si tener llamado read(), then it probably indicates that there's more data available than you've read, and you should carry on reading until you've got it all. There's only a problem here if either the call to read() fails or blocks after select has indicated that it's readable, or if you have reason to believe that there should be no data following what you've already read.

respondido 08 nov., 11:19

I am doing a READ after both selects. 1st select is used to get the file size(reading start to end). 2nd select is used to read and write it to a local file(1 byte at a time). How do i make the second select timeout? - maheshg

Si el segundo select returns immediately, and indicates that the socket is readable, then just read from it. It probably means that the server sent both the size and the following data together, so that both are available to read. Or is the problem that you're doing that, and the second read blocks when select says it shouldn't? - Mike Seymour

to get the size, i do an actual read from start to end (weird but true), then the second select tries to poll and read from the same socket to write the data to a local file. - maheshg

@user1035818: I'm afraid I'm finding it rather hard to follow this. You say you read all the data, and then want to read it again? You can't do that - once it's read, it's gone from the socket. Or is the second read supposed to read different data? Perhaps you could post some code, so I can see what you're actually doing? - Mike Seymour

my bad, what you said earlier is correct, it gives me the size in the header and then the actual file, so the first read (after select1) reads the header and the second read(after second select) reads the remaining actual file. so for the second select to timeout does read have any effect on select's timer? maybe somehow the socket buffer got cleared or invalidated and now the second select has to redo fetch all data again(but the timer is now reduced to what was unused by first select and is not enough causing timeout, just a thought) - maheshg

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.