nsprpub/pr/src/cplus/rcfileio.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/src/cplus/rcfileio.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,129 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 +** Class definitions for normal and special file I/O (ref: prio.h)
    1.11 +*/
    1.12 +
    1.13 +#if defined(_RCFILEIO_H)
    1.14 +#else
    1.15 +#define _RCFILEIO_H
    1.16 +
    1.17 +#include "rcio.h"
    1.18 +#include "rctime.h"
    1.19 +
    1.20 +/*
    1.21 +** One would normally create a concrete class, such as RCFileIO, but then
    1.22 +** pass around more generic references, ie., RCIO.
    1.23 +**
    1.24 +** This subclass of RCIO hides (makes private) the methods that are not
    1.25 +** applicable to normal files.
    1.26 +*/
    1.27 +
    1.28 +class RCFileInfo;
    1.29 +
    1.30 +class PR_IMPLEMENT(RCFileIO): public RCIO
    1.31 +{
    1.32 +public:
    1.33 +    RCFileIO();
    1.34 +    virtual ~RCFileIO();
    1.35 +
    1.36 +    virtual PRInt64     Available();
    1.37 +    virtual PRStatus    Close();
    1.38 +    static  PRStatus    Delete(const char *name);
    1.39 +    virtual PRStatus    FileInfo(RCFileInfo* info) const;
    1.40 +    static  PRStatus    FileInfo(const char *name, RCFileInfo* info);
    1.41 +    virtual PRStatus    Fsync();
    1.42 +    virtual PRStatus    Open(const char *name, PRIntn flags, PRIntn mode);
    1.43 +    virtual PRInt32     Read(void *buf, PRSize amount);
    1.44 +    virtual PRInt64     Seek(PRInt64 offset, RCIO::Whence how);
    1.45 +    virtual PRInt32     Write(const void *buf, PRSize amount);
    1.46 +    virtual PRInt32     Writev(
    1.47 +                            const PRIOVec *iov, PRSize size,
    1.48 +                            const RCInterval& timeout);
    1.49 +
    1.50 +private:
    1.51 +
    1.52 +    /* These methods made private are unavailable for this object */
    1.53 +    RCFileIO(const RCFileIO&);
    1.54 +    void operator=(const RCFileIO&);
    1.55 +
    1.56 +    RCIO*       Accept(RCNetAddr* addr, const RCInterval& timeout);
    1.57 +    PRInt32     AcceptRead(
    1.58 +                    RCIO **newfd, RCNetAddr **address, void *buffer,
    1.59 +                    PRSize amount, const RCInterval& timeout);
    1.60 +    PRStatus    Bind(const RCNetAddr& addr);
    1.61 +    PRStatus    Connect(const RCNetAddr& addr, const RCInterval& timeout);
    1.62 +    PRStatus    GetLocalName(RCNetAddr *addr) const;
    1.63 +    PRStatus    GetPeerName(RCNetAddr *addr) const;
    1.64 +    PRStatus    GetSocketOption(PRSocketOptionData *data) const;
    1.65 +    PRStatus    Listen(PRIntn backlog);
    1.66 +    PRInt16     Poll(PRInt16 in_flags, PRInt16 *out_flags);
    1.67 +    PRInt32     Recv(
    1.68 +                    void *buf, PRSize amount, PRIntn flags,
    1.69 +                    const RCInterval& timeout);
    1.70 +    PRInt32     Recvfrom(
    1.71 +                    void *buf, PRSize amount, PRIntn flags,
    1.72 +                    RCNetAddr* addr, const RCInterval& timeout);
    1.73 +    PRInt32     Send(
    1.74 +                    const void *buf, PRSize amount, PRIntn flags,
    1.75 +                    const RCInterval& timeout);
    1.76 +    PRInt32     Sendto(
    1.77 +                    const void *buf, PRSize amount, PRIntn flags,
    1.78 +                    const RCNetAddr& addr,
    1.79 +                    const RCInterval& timeout);
    1.80 +    PRStatus    SetSocketOption(const PRSocketOptionData *data);
    1.81 +    PRStatus    Shutdown(RCIO::ShutdownHow how);
    1.82 +    PRInt32     TransmitFile(
    1.83 +                    RCIO *source, const void *headers,
    1.84 +                    PRSize hlen, RCIO::FileDisposition flags,
    1.85 +                    const RCInterval& timeout);
    1.86 +public:
    1.87 +
    1.88 +    /*
    1.89 +    ** The following function return a valid normal file object,
    1.90 +    ** Such objects can be used for scanned input and console output.
    1.91 +    */
    1.92 +    typedef enum {
    1.93 +        input = PR_StandardInput,
    1.94 +        output = PR_StandardOutput,
    1.95 +        error = PR_StandardError
    1.96 +    } SpecialFile;
    1.97 +
    1.98 +    static RCIO *GetSpecialFile(RCFileIO::SpecialFile special);
    1.99 +
   1.100 +};  /* RCFileIO */
   1.101 +
   1.102 +class PR_IMPLEMENT(RCFileInfo): public RCBase
   1.103 +{
   1.104 +public:
   1.105 +    typedef enum {
   1.106 +        file = PR_FILE_FILE,
   1.107 +        directory = PR_FILE_DIRECTORY,
   1.108 +        other = PR_FILE_OTHER
   1.109 +    } FileType;
   1.110 +
   1.111 +public:
   1.112 +    RCFileInfo();
   1.113 +    RCFileInfo(const RCFileInfo&);
   1.114 +
   1.115 +    virtual ~RCFileInfo();
   1.116 +
   1.117 +    PRInt64 Size() const;
   1.118 +    RCTime CreationTime() const;
   1.119 +    RCTime ModifyTime() const;
   1.120 +    RCFileInfo::FileType Type() const;
   1.121 +
   1.122 +friend PRStatus RCFileIO::FileInfo(RCFileInfo*) const;
   1.123 +friend PRStatus RCFileIO::FileInfo(const char *name, RCFileInfo*);
   1.124 +
   1.125 +private:
   1.126 +    PRFileInfo64 info;
   1.127 +};  /* RCFileInfo */
   1.128 +
   1.129 +inline RCFileInfo::RCFileInfo(): RCBase() { }
   1.130 +inline PRInt64 RCFileInfo::Size() const { return info.size; }
   1.131 +
   1.132 +#endif /* defined(_RCFILEIO_H) */

mercurial