有人可以向我解释这段代码的粗体部分在做什么吗?
while ( 1 )
{
**FD_ZERO( &readfds );
FD_SET( 0, &readfds ); /* add stdin */
FD_SET( sock, &readfds );**
/* BLOCK on select() */
**select( FD_SETSIZE, &readfds, NULL, NULL, NULL );**
**if ( FD_ISSET( 0, &readfds ) )**
{
char msg[1024];
scanf( "%[^\n]", msg ); /* read everything up to the '\n' */
getchar(); /* read (skip) the '\n' character */
/* write the message to the socket connection */
int n = write( sock, msg, strlen( msg ) );
if ( n < strlen( msg ) )
{
perror( "write() failed" );
return EXIT_FAILURE;
}
}
**if ( FD_ISSET( sock, &readfds ) )**
{
char buffer[1024];
int n = read( sock, buffer, 1024 );
if ( n < 1 )
{
perror( "read() failed" );
}
else
{
buffer[n] = '\0';
printf( "Rcvd msg from server: %s", buffer );
}
}
}