반응형

send/recv 와 write/read함수의 차이?

UNIX/Linux에서 모든 장치/자원은 FILE.
그래서 소켓이란 자원 역시 read/write라는 인터페이스로 입출력을 수행.
recv/send는 소켓 전용 인터페이스로 뒤에 옵션이 더 있음.
UNIX/Linux에선 아무거나 써도 무방하나,Windows에서 소켓은 recv/send만 사용가능




     #include <sys/types.h>
     #include <sys/socket.h>
     #include <sys/uio.h>

     ssize_t recv(int s, void *buf, size_t len, int flags);

     ssize_t recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);

     ssize_t recvmsg(int s, struct msghdr *msg, int flags);




flags 값.

MSG_OOB         
- Read any out-of-band  data  present  on  the socket rather than the regular in-band data.

MSG_PEEK
- Peek at the data present on the socket.  The data  is returned, but not consumed to allow  a subsequent receive operation  to  see  the same data.

MSG_WAITALL
- Messages are blocked until the  full  amount of  data  requested  is returned. The recv() function can return a smaller amount of data  if  a  signal  is  caught, the connection is   terminated, MSG_PEEK is specified, or if  an error is pending for the socket.

MSG_DONTWAIT
- Pending messages received on the  connection are  returned.  If  data is unavailable, the function does not block.  This  behavior  is the  equivalent  to specifying O_NONBLOCK on the file descriptor of a socket, except that write requests are unaffected.


반응형
Posted by 공간사랑
,