<commit_before>#ifndef TAMER_FD_HH
#define TAMER_FD_HH 1
/* Copyright (c) 2007-2012, <NAME>
 * Copyright (c) 2007, Regents of the University of California
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, subject to the conditions
 * listed in the Tamer LICENSE file. These conditions include: you must
 * preserve this copyright notice, and you cannot mention the copyright
 * holders in advertising related to the Software without their permission.
 * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
 * notice is a summary of the Tamer LICENSE file; the license in that file is
 * legally binding.
 */
#include <tamer/tamer.hh>
#include <tamer/lock.hh>
#include <tamer/ref.hh>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <vector>
namespace tamer {

/** @file <tamer/fd.hh>
 *  @brief  Event-based file descriptor wrapper class.
 */

class fd {
    struct fdimp;

  public:
    typedef ref_ptr<fdimp> fd::*unspecified_bool_type;
    enum { default_backlog = 128 };

    inline fd();
    explicit inline fd(int f);
    inline fd(const fd &f);
    inline ~fd();

    inline fd &operator=(const fd &f);

    static void open(const char *filename, int flags, mode_t mode,
		     event<fd> result);
    static inline void open(const char *filename, int flags, event<fd> result);
    static fd open(const char *filename, int flags, mode_t mode = 0777);

    static fd socket(int domain, int type, int protocol);
    static int pipe(fd &rfd, fd &wfd);

    inline bool valid() const;
    inline operator unspecified_bool_type() const;
    inline bool operator!() const;
    inline int error() const;
    inline int value() const;

    inline void at_close(event<> e);
    event<> closer();
    inline void close(event<int> done);
    inline void close();
    inline void error_close(int errcode);

    void read(void *buf, size_t size, size_t &nread, event<int> done);
    inline void read(void *buf, size_t size, size_t &nread, event<> done);
    inline void read(void *buf, size_t size, event<int> done);
    inline void read(void *buf, size_t size, event<> done);
    void read_once(void *buf, size_t size, size_t &nread, event<int> done);
    inline void read_once(void *buf, size_t size, size_t &nread, event<> done);

    void write(const void *buf, size_t size, size_t &nwritten, event<int> done);
    inline void write(const void *buf, size_t size, size_t &nwritten, event<> done);
    inline void write(const void *buf, size_t size, event<int> done);
    inline void write(const void *buf, size_t size, event<> done);
    void write(std::string buf, size_t &nwritten, event<int> done);
    inline void write(const std::string &buf, size_t &nwritten, event<> done);
    inline void write(const std::string &buf, event<int> done);
    inline void write(const std::string &buf, event<> done);
    void write_once(const void *buf, size_t size, size_t &nwritten, event<int> done);
    inline void write_once(const void *buf, size_t size, size_t &nwritten, event<> done);

    inline void sendmsg(const void *buf, size_t size, int transfer_fd,
			event<int> done);
    inline void sendmsg(const void *buf, size_t size, event<int> done);

    void fstat(struct stat &stat, event<int> done);

    int listen(int backlog = default_backlog);
    int bind(const struct sockaddr *addr, socklen_t addrlen);
    void accept(struct sockaddr *addr, socklen_t *addrlen, event<fd> result);
    inline void accept(event<fd> result);
    void connect(const struct sockaddr *addr, socklen_t addrlen,
		 event<int> done);

    static int make_nonblocking(int f);
    static int make_blocking(int f);
    inline int make_nonblocking();

  private:

    struct fdcloser {<commit_msg>Nit: Don't declare this inline, it's not.<commit_after>#ifndef TAMER_FD_HH
#define TAMER_FD_HH 1
/* Copyright (c) 2007-2012, <NAME>
 * Copyright (c) 2007, Regents of the University of California
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, subject to the conditions
 * listed in the Tamer LICENSE file. These conditions include: you must
 * preserve this copyright notice, and you cannot mention the copyright
 * holders in advertising related to the Software without their permission.
 * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
 * notice is a summary of the Tamer LICENSE file; the license in that file is
 * legally binding.
 */
#include <tamer/tamer.hh>
#include <tamer/lock.hh>
#include <tamer/ref.hh>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <vector>
namespace tamer {

/** @file <tamer/fd.hh>
 *  @brief  Event-based file descriptor wrapper class.
 */

class fd {
    struct fdimp;

  public:
    typedef ref_ptr<fdimp> fd::*unspecified_bool_type;
    enum { default_backlog = 128 };

    inline fd();
    explicit inline fd(int f);
    inline fd(const fd &f);
    inline ~fd();

    inline fd &operator=(const fd &f);

    static void open(const char *filename, int flags, mode_t mode,
		     event<fd> result);
    static inline void open(const char *filename, int flags, event<fd> result);
    static fd open(const char *filename, int flags, mode_t mode = 0777);

    static fd socket(int domain, int type, int protocol);
    static int pipe(fd &rfd, fd &wfd);

    inline bool valid() const;
    inline operator unspecified_bool_type() const;
    inline bool operator!() const;
    inline int error() const;
    inline int value() const;

    inline void at_close(event<> e);
    event<> closer();
    inline void close(event<int> done);
    inline void close();
    inline void error_close(int errcode);

    void read(void *buf, size_t size, size_t &nread, event<int> done);
    inline void read(void *buf, size_t size, size_t &nread, event<> done);
    inline void read(void *buf, size_t size, event<int> done);
    inline void read(void *buf, size_t size, event<> done);
    void read_once(void *buf, size_t size, size_t &nread, event<int> done);
    inline void read_once(void *buf, size_t size, size_t &nread, event<> done);

    void write(const void *buf, size_t size, size_t &nwritten, event<int> done);
    inline void write(const void *buf, size_t size, size_t &nwritten, event<> done);
    inline void write(const void *buf, size_t size, event<int> done);
    inline void write(const void *buf, size_t size, event<> done);
    void write(std::string buf, size_t &nwritten, event<int> done);
    inline void write(const std::string &buf, size_t &nwritten, event<> done);
    inline void write(const std::string &buf, event<int> done);
    inline void write(const std::string &buf, event<> done);
    void write_once(const void *buf, size_t size, size_t &nwritten, event<int> done);
    inline void write_once(const void *buf, size_t size, size_t &nwritten, event<> done);

    void sendmsg(const void *buf, size_t size, int transfer_fd, event<int> done);
    inline void sendmsg(const void *buf, size_t size, event<int> done);

    void fstat(struct stat &stat, event<int> done);

    int listen(int backlog = default_backlog);
    int bind(const struct sockaddr *addr, socklen_t addrlen);
    void accept(struct sockaddr *addr, socklen_t *addrlen, event<fd> result);
    inline void accept(event<fd> result);
    void connect(const struct sockaddr *addr, socklen_t addrlen,
		 event<int> done);

    static int make_nonblocking(int f);
    static int make_blocking(int f);
    inline int make_nonblocking();

  private:

    struct fdcloser {
{'fraction_non_alphanumeric': 0.1086070791953145, 'fraction_numerical': 0.005092946269416858, 'mean_word_length': 4.094033722438391, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2789460', 'n_tokens_mistral': 2493, 'n_tokens_neox': 2396, 'n_words': 935}