Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Weird socket problem

Name: Anonymous 2011-01-15 1:57

/prog/ I come to you for help with my superior ENTERPRISE(tm) programming.

The test environment is Windows XP running under VirtualBox and I'm using Python to execute the program.

Basically I want to send n amount of data with socket.send and have a reliable estimate on how long it has taken to send n bytes. I am using sockets with a timeout of 15 seconds. Let me explain in my own words why I haven't been able to do what I want:

Apparently send works with network buffers. It just adds what I'm trying to send to the network buffer and returns the amount of data it passed to this buffer, only ever blocking/sleeping when the buffer is full. So in other words, send doesn't actually send anything. So even when I send large amounts of data, 100MB or more, send returns instantly, WTF.

Shouldn't the buffer be a reasonable size, and if send really does work like this how am I to determine how many bytes have been actually sent?

Note: I don't want to use a protocol, i.e. have the client return how many bytes received because I'm working on a socket class.

Note: I don't have this problem with recv it seems . . .

Please help me /prog/, no troll.

Name: Anonymous 2011-01-16 7:08

OP here. I'm bumping with my solution.

So I kept going on and on about buffers. I ended up turning them off completely, but only for send. Now it works perfectly!

In Python I do that by using (after I create a socket):

sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 0)


So this means send isn't buffered at all. You told me to accept the fact that these functions are buffed, alas' I have done it my way and it works. No more buffering for send.

With this implementation, send actually seems to block until all of the data you have passed it has really been sent, thus it can even be used to measure average upstream if you fully saturate the upstream for at least 4 seconds.

I'm sure send may not send all the bytes you pass it so a loop will probably still be needed.

I hope this helps someone as /prog/ has helped me.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List