Are you sure the struct timeval should be used as a parameter?
I suppose timeout should be rather passed as int (or unsigned int), in milliseconds:

int nTimeout = 30000; // 30 seconds...