tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

rcio.h (4119B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 /*
      7 ** Base class definitions for I/O (ref: prio.h)
      8 **
      9 ** This class is a virtual base class. Construction must be done by a
     10 ** subclass, but the I/O operations can be done on a RCIO object reference.
     11 */
     12 
     13 #if defined(_RCIO_H)
     14 #else
     15 #define _RCIO_H
     16 
     17 #include "rcbase.h"
     18 #include "rcnetdb.h"
     19 #include "rcinrval.h"
     20 
     21 #include "prio.h"
     22 
     23 class RCFileInfo;
     24 
     25 class PR_IMPLEMENT(RCIO): public RCBase
     26 {
     27 public:
     28    typedef enum {
     29        open = PR_TRANSMITFILE_KEEP_OPEN,   /* socket is left open after file
     30                                             * is transmitted. */
     31        close = PR_TRANSMITFILE_CLOSE_SOCKET/* socket is closed after file
     32                                             * is transmitted. */
     33    } FileDisposition;
     34 
     35    typedef enum {
     36        set = PR_SEEK_SET,                  /* Set to value specified */
     37        current = PR_SEEK_CUR,              /* Seek relative to current position */
     38        end = PR_SEEK_END                   /* seek past end of current eof */
     39    } Whence;
     40 
     41    typedef enum {
     42        recv = PR_SHUTDOWN_RCV,             /* receives will be disallowed */
     43        send = PR_SHUTDOWN_SEND,            /* sends will be disallowed */
     44        both = PR_SHUTDOWN_BOTH             /* sends & receives will be disallowed */
     45    } ShutdownHow;
     46 
     47 public:
     48    virtual ~RCIO();
     49 
     50    virtual RCIO*       Accept(RCNetAddr* addr, const RCInterval& timeout) = 0;
     51    virtual PRInt32     AcceptRead(
     52        RCIO **nd, RCNetAddr **raddr, void *buf,
     53        PRSize amount, const RCInterval& timeout) = 0;
     54    virtual PRInt64     Available() = 0;
     55    virtual PRStatus    Bind(const RCNetAddr& addr) = 0;
     56    virtual PRStatus    Close() = 0;
     57    virtual PRStatus    Connect(
     58        const RCNetAddr& addr,
     59        const RCInterval& timeout) = 0;
     60    virtual PRStatus    FileInfo(RCFileInfo *info) const = 0;
     61    virtual PRStatus    Fsync() = 0;
     62    virtual PRStatus    GetLocalName(RCNetAddr *addr) const = 0;
     63    virtual PRStatus    GetPeerName(RCNetAddr *addr) const = 0;
     64    virtual PRStatus    GetSocketOption(PRSocketOptionData *data) const = 0;
     65    virtual PRStatus    Listen(PRIntn backlog) = 0;
     66    virtual PRStatus    Open(const char *name, PRIntn flags, PRIntn mode) = 0;
     67    virtual PRInt16     Poll(PRInt16 in_flags, PRInt16 *out_flags) = 0;
     68    virtual PRInt32     Read(void *buf, PRSize amount) = 0;
     69    virtual PRInt32     Recv(
     70        void *buf, PRSize amount, PRIntn flags,
     71        const RCInterval& timeout) = 0;
     72    virtual PRInt32     Recvfrom(
     73        void *buf, PRSize amount, PRIntn flags,
     74        RCNetAddr* addr, const RCInterval& timeout) = 0;
     75    virtual PRInt64     Seek(PRInt64 offset, Whence how) = 0;
     76    virtual PRInt32     Send(
     77        const void *buf, PRSize amount, PRIntn flags,
     78        const RCInterval& timeout) = 0;
     79    virtual PRInt32     Sendto(
     80        const void *buf, PRSize amount, PRIntn flags,
     81        const RCNetAddr& addr,
     82        const RCInterval& timeout) = 0;
     83    virtual PRStatus    SetSocketOption(const PRSocketOptionData *data) = 0;
     84    virtual PRStatus    Shutdown(ShutdownHow how) = 0;
     85    virtual PRInt32     TransmitFile(
     86        RCIO *source, const void *headers,
     87        PRSize hlen, RCIO::FileDisposition flags,
     88        const RCInterval& timeout) = 0;
     89    virtual PRInt32     Write(const void *buf, PRSize amount) = 0;
     90    virtual PRInt32     Writev(
     91        const PRIOVec *iov, PRSize size,
     92        const RCInterval& timeout) = 0;
     93 
     94 protected:
     95    typedef enum {
     96        file = PR_DESC_FILE,
     97        tcp = PR_DESC_SOCKET_TCP,
     98        udp = PR_DESC_SOCKET_UDP,
     99        layered = PR_DESC_LAYERED
    100    } RCIOType;
    101 
    102    RCIO(RCIOType);
    103 
    104    PRFileDesc *fd;  /* where the real code hides */
    105 
    106 private:
    107    /* no default construction and no copies allowed */
    108    RCIO();
    109    RCIO(const RCIO&);
    110 
    111 };  /* RCIO */
    112 
    113 #endif /* defined(_RCIO_H) */
    114 
    115 /* RCIO.h */