??????????read
ssize_t read(int fd??void *buf??size_t nbyte)
????read??????????fd?ж??????.??????? ???read???????????????????????????????0 ?????????????????????С??0????????????.????????EINTR??????????ж????? ??? ?????ECONNREST??????????????????. ????????????????д?????????????.
int my_read(int fd??void *buffer??int length)
{
int bytes_left;
int bytes_read;
char *ptr;
bytes_left=length;
while(bytes_left>0)
{
bytes_read=read(fd??ptr??bytes_read);
if(bytes_read<0)
{
if(errno==EINTR)
bytes_read=0;
else
return(-1);
}
else if(bytes_read==0)
break;
bytes_left-=bytes_read;
ptr+=bytes_read;
}
return(length-bytes_left);
}
????????????
??????????????????????????????????????????????????????.??????????????????.??????????·??
/* ???????????д */
struct my_struct my_struct_client;
write(fd??(void *)&my_struct_client??sizeof(struct my_struct);
/* ???????*/
char buffer[sizeof(struct my_struct)];
struct *my_struct_server;
read(fd??(void *)buffer??sizeof(struct my_struct));
my_struct_server=(struct my_struct *)buffer;
??????????????????????????????????????char????????????.???????????????? ????????????б????????????????(????????????????κ?????????????????????????????)
????6.1 recv??send
????recv??send?????????read??write????????.?????????? ?????????????????д????.
????int recv(int sockfd??void *buf??int len??int flags)
????int send(int sockfd??void *buf??int len??int flags)
??????????????????read??write????????????????????0?????????μ????
_______________________________________________________________
| MSG_DONTROUTE | ??????? |
| MSG_OOB | ????????????????? |
| MSG_PEEK | ????????????????????????????? |
| MSG_WAITALL | ??????????? |
|--------------------------------------------------------------|
????MSG_DONTROUTE:??send??????????.??????????IP.???????????????????棬??б???????.???????????????????·?????????.
????MSG_OOB:??????????????????????.???????????????????????.
????MSG_PEEK:??recv?????????????????????????????ж????????????????????????????.?????′ζ????????????????????.??????ж???????д??????????????????.
????MSG_WAITALL??recv??????????????????????е??????????????.??????????????recv?????????????????????????????? ??????????. 1)???????????????????????????????.?????????len 2)??????????????β???????????????.?????С??len 3)?????????????????????-1?????????????????????(errno)
????MSG_NOSIGNAL is a flag used by send() in some implementations of the Berkeley sockets API.
????This flag requests that the implementation does not to send a SIGPIPE signal on errors on stream oriented sockets when the other end breaks the connection. The EPIPE error is still returned as normal.
????Though it is in some Berkely sockets APIs (notably Linux) it does not exist in what some refer to as the reference implementation?? FreeBSD?? which instead uses a socket option SO_NOSIGPIPE?. ??????????????????????????????????????????SIG_PIPE???????3????????
???????flags?0?????read??write????????.????????????????????????????????????????? Linux Programmer's Manual??????????.