Is it a good idea to call recv()
one byte at a time with sockets (in terms of performance)? Does it cause a context switch? If so why is there a context switch?
Calling recv()
one byte at a time will negatively impact performance. There is a certain amount of overhead on each call -- the transition to kernel mode, file descriptor lookup, dispatch to the protocol-specific driver, buffer/queue locking, etc. Calling recv()
with larger buffers greatly decreases the average overhead per byte.