tcp/ip

作者: littleDinosaur | 来源:发表于2017-05-27 18:39 被阅读0次

    sock_map_fd
    -----------sock_alloc_file
    -----------fd_install

    sock_alloc(**void**) //return socket *

    static const struct file_operations socket_file_ops = {
        .owner =    THIS_MODULE,
        .llseek =   no_llseek,
        .read_iter =    sock_read_iter,
        .write_iter =   sock_write_iter,
        .poll =     sock_poll,
        .unlocked_ioctl = sock_ioctl,
    #ifdef CONFIG_COMPAT
        .compat_ioctl = compat_sock_ioctl,
    #endif
        .mmap =     sock_mmap,
        .release =  sock_close,
        .fasync =   sock_fasync,
        .sendpage = sock_sendpage,
        .splice_write = generic_splice_sendpage,
        .splice_read =  sock_splice_read,
    };
    

    /linux-2.6.38.8/net/ipv4/tcp.c

    int sock_map_fd(struct socket *sock, int flags)
    {
        struct file *newfile;
        int fd = sock_alloc_file(sock, &newfile, flags);
    
        if (likely(fd >= 0))
            fd_install(fd, newfile);
    
        return fd;
    }
    
    
    static int sock_alloc_file(struct socket *sock, struct file **f, int flags){
              struct file *file;
        ..............
         file = alloc_file(&path, FMODE_READ | FMODE_WRITE,
              &socket_file_ops);
       sock->file = file;
       file->private_data = sock;
    }
    

    相关文章

      网友评论

          本文标题:tcp/ip

          本文链接:https://www.haomeiwen.com/subject/togqfxtx.html