/** * \file misc/socket.hh * \brief Socket related syscalls. */ #pragma once #include #include #include #include #include "misc/fd.hh" #include "misc/sys-wrapper.hh" namespace sys { /** * \brief accept(2). */ inline auto accept = make_wrapper(::accept); /** * \brief bind(2). */ inline auto bind = make_wrapper(::bind); /** * \brief connect(2). */ inline auto connect = make_wrapper(::connect); static int fcntl_wrapper(int fildes, int opts) { auto flags = ::fcntl(fildes, F_GETFL); return ::fcntl(fildes, F_SETFL, flags | opts); } /** * \brief fcntl(2). * * Since fcntl is a variadic syscall we need to call a helper function * with a fixed number of parameter to create a wrapper out of it. */ inline auto fcntl_set = make_wrapper(fcntl_wrapper); /** * \brief getsockname(2). */ inline auto getsockname = make_wrapper(::getsockname); /** * \brief listen(2). */ inline auto listen = make_wrapper(::listen); /** * \brief lseek(2). */ inline auto lseek = make_wrapper(::lseek); /** * \brief read(2). */ inline auto read = make_wrapper(::read); /** * \brief recv(2). */ inline auto recv = make_wrapper(::recv); /** * \brief send(2). */ inline auto send = make_wrapper(::send); /** * \brief sendfile(2). */ inline auto sendfile = make_wrapper(::sendfile); /** * \brief setsockopt(2). */ inline auto setsockopt = make_wrapper(::setsockopt); /** * \brief getsockopt(2). */ inline auto getsockopt = make_wrapper(::getsockopt); /** * \brief socket(2). */ inline auto socket = make_wrapper(::socket); /** * \brief getpeername(2). */ inline auto getpeername = make_wrapper(::getpeername); } // namespace sys