Compare the results of recv/send with the parameter passed and detect whether the system has no free buffer space for send() or has no data anymore for recv(). This dramatically reduces the number of syscalls (by about 23%).