Skip to content
Snippets Groups Projects
  • Nadav Har'El's avatar
    9478a14d
    file: reduce boiler-plate code in special files · 9478a14d
    Nadav Har'El authored
    
    Each implementation of "struct file" needs to implement 8 different file
    operations. Most special file implementations, such as pipe, socketpair,
    epoll and timerfd, don't support many of these operations. We had in
    unsupported.h functions that can be reused for the unsupported operation,
    but this resulted in a lot of ugly boiler-plate code.
    
    Instead, this patch switches to a cleaner, more C++-like, method:
    It defines a new "file" subclass, called "special_file", which implements
    all file operations except close(), with a default implementation identical
    to the old unsupported.h implementations.
    
    The files of pipe(), socketpair(), timerfd() and epoll_create() now inherit
    from special_file, and only override the file operations they really want
    to implement.
    
    Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
    Signed-off-by: default avatarAvi Kivity <avi@cloudius-systems.com>
    9478a14d
    History
    file: reduce boiler-plate code in special files
    Nadav Har'El authored
    
    Each implementation of "struct file" needs to implement 8 different file
    operations. Most special file implementations, such as pipe, socketpair,
    epoll and timerfd, don't support many of these operations. We had in
    unsupported.h functions that can be reused for the unsupported operation,
    but this resulted in a lot of ugly boiler-plate code.
    
    Instead, this patch switches to a cleaner, more C++-like, method:
    It defines a new "file" subclass, called "special_file", which implements
    all file operations except close(), with a default implementation identical
    to the old unsupported.h implementations.
    
    The files of pipe(), socketpair(), timerfd() and epoll_create() now inherit
    from special_file, and only override the file operations they really want
    to implement.
    
    Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
    Signed-off-by: default avatarAvi Kivity <avi@cloudius-systems.com>