linux 通用IO

open(),read(),write(),close()可以应用于管道,FIFO,socket,或者终端等所有文件类型执行IO操作。

lseek()并不适用于所有类型的文件。不允许将lseek()应用于管道,FIFO,socket或者终端,只要合情合理,也可以将lseek应用于设备。例如在磁盘或磁带上查找一处具体位置。

cp test test.old

cp test /dev/pts/0

cp /dev/pts/0 test

cp /dev/pts/0 /dev/pts/1

[root@250-shiyan pts]# echo "wo shi " > /dev/pts/0
[root@250-shiyan ~]# cp /dev/pts/1 b.txt
fjei
sfoei
rifeo
wfowef
[root@250-shiyan ~]# cat b.txt
fjei
sfoei
rifeo
wfowef

 

/usr/include/netinet/in.h 

/* Structure describing an Internet socket address.  */
struct sockaddr_in
  {
    __SOCKADDR_COMMON (sin_);
    in_port_t sin_port;                 /* Port number.  */
    struct in_addr sin_addr;            /* Internet address.  */

    /* Pad to size of `struct sockaddr‘.  */
    unsigned char sin_zero[sizeof (struct sockaddr) -
                           __SOCKADDR_COMMON_SIZE -
                           sizeof (in_port_t) -
                           sizeof (struct in_addr)];
  };

/* Ditto, for IPv6.  */
struct sockaddr_in6
  {
    __SOCKADDR_COMMON (sin6_);
    in_port_t sin6_port;        /* Transport layer port # */
    uint32_t sin6_flowinfo;     /* IPv6 flow information */
    struct in6_addr sin6_addr;  /* IPv6 address */
    uint32_t sin6_scope_id;     /* IPv6 scope-id */
  };

/usr/include/sys/socket.h

/* Create a new socket of type TYPE in domain DOMAIN, using
   protocol PROTOCOL.  If PROTOCOL is zero, one is chosen automatically.
   Returns a file descriptor for the new socket, or -1 for errors.  */
extern int socket (int __domain, int __type, int __protocol) __THROW;


socketpair()系统调用只能用在unix domain中,
/* Create two new sockets, of type TYPE in domain DOMAIN and using
   protocol PROTOCOL, which are connected to each other, and put file
   descriptors for them in FDS[0] and FDS[1].  If PROTOCOL is zero,
   one will be chosen automatically.  Returns 0 on success, -1 for errors.  */
extern int socketpair (int __domain, int __type, int __protocol,
                       int __fds[2]) __THROW;

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。