nsprpub/pr/src/cplus/rcfileio.h

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 ** Class definitions for normal and special file I/O (ref: prio.h)
michael@0 8 */
michael@0 9
michael@0 10 #if defined(_RCFILEIO_H)
michael@0 11 #else
michael@0 12 #define _RCFILEIO_H
michael@0 13
michael@0 14 #include "rcio.h"
michael@0 15 #include "rctime.h"
michael@0 16
michael@0 17 /*
michael@0 18 ** One would normally create a concrete class, such as RCFileIO, but then
michael@0 19 ** pass around more generic references, ie., RCIO.
michael@0 20 **
michael@0 21 ** This subclass of RCIO hides (makes private) the methods that are not
michael@0 22 ** applicable to normal files.
michael@0 23 */
michael@0 24
michael@0 25 class RCFileInfo;
michael@0 26
michael@0 27 class PR_IMPLEMENT(RCFileIO): public RCIO
michael@0 28 {
michael@0 29 public:
michael@0 30 RCFileIO();
michael@0 31 virtual ~RCFileIO();
michael@0 32
michael@0 33 virtual PRInt64 Available();
michael@0 34 virtual PRStatus Close();
michael@0 35 static PRStatus Delete(const char *name);
michael@0 36 virtual PRStatus FileInfo(RCFileInfo* info) const;
michael@0 37 static PRStatus FileInfo(const char *name, RCFileInfo* info);
michael@0 38 virtual PRStatus Fsync();
michael@0 39 virtual PRStatus Open(const char *name, PRIntn flags, PRIntn mode);
michael@0 40 virtual PRInt32 Read(void *buf, PRSize amount);
michael@0 41 virtual PRInt64 Seek(PRInt64 offset, RCIO::Whence how);
michael@0 42 virtual PRInt32 Write(const void *buf, PRSize amount);
michael@0 43 virtual PRInt32 Writev(
michael@0 44 const PRIOVec *iov, PRSize size,
michael@0 45 const RCInterval& timeout);
michael@0 46
michael@0 47 private:
michael@0 48
michael@0 49 /* These methods made private are unavailable for this object */
michael@0 50 RCFileIO(const RCFileIO&);
michael@0 51 void operator=(const RCFileIO&);
michael@0 52
michael@0 53 RCIO* Accept(RCNetAddr* addr, const RCInterval& timeout);
michael@0 54 PRInt32 AcceptRead(
michael@0 55 RCIO **newfd, RCNetAddr **address, void *buffer,
michael@0 56 PRSize amount, const RCInterval& timeout);
michael@0 57 PRStatus Bind(const RCNetAddr& addr);
michael@0 58 PRStatus Connect(const RCNetAddr& addr, const RCInterval& timeout);
michael@0 59 PRStatus GetLocalName(RCNetAddr *addr) const;
michael@0 60 PRStatus GetPeerName(RCNetAddr *addr) const;
michael@0 61 PRStatus GetSocketOption(PRSocketOptionData *data) const;
michael@0 62 PRStatus Listen(PRIntn backlog);
michael@0 63 PRInt16 Poll(PRInt16 in_flags, PRInt16 *out_flags);
michael@0 64 PRInt32 Recv(
michael@0 65 void *buf, PRSize amount, PRIntn flags,
michael@0 66 const RCInterval& timeout);
michael@0 67 PRInt32 Recvfrom(
michael@0 68 void *buf, PRSize amount, PRIntn flags,
michael@0 69 RCNetAddr* addr, const RCInterval& timeout);
michael@0 70 PRInt32 Send(
michael@0 71 const void *buf, PRSize amount, PRIntn flags,
michael@0 72 const RCInterval& timeout);
michael@0 73 PRInt32 Sendto(
michael@0 74 const void *buf, PRSize amount, PRIntn flags,
michael@0 75 const RCNetAddr& addr,
michael@0 76 const RCInterval& timeout);
michael@0 77 PRStatus SetSocketOption(const PRSocketOptionData *data);
michael@0 78 PRStatus Shutdown(RCIO::ShutdownHow how);
michael@0 79 PRInt32 TransmitFile(
michael@0 80 RCIO *source, const void *headers,
michael@0 81 PRSize hlen, RCIO::FileDisposition flags,
michael@0 82 const RCInterval& timeout);
michael@0 83 public:
michael@0 84
michael@0 85 /*
michael@0 86 ** The following function return a valid normal file object,
michael@0 87 ** Such objects can be used for scanned input and console output.
michael@0 88 */
michael@0 89 typedef enum {
michael@0 90 input = PR_StandardInput,
michael@0 91 output = PR_StandardOutput,
michael@0 92 error = PR_StandardError
michael@0 93 } SpecialFile;
michael@0 94
michael@0 95 static RCIO *GetSpecialFile(RCFileIO::SpecialFile special);
michael@0 96
michael@0 97 }; /* RCFileIO */
michael@0 98
michael@0 99 class PR_IMPLEMENT(RCFileInfo): public RCBase
michael@0 100 {
michael@0 101 public:
michael@0 102 typedef enum {
michael@0 103 file = PR_FILE_FILE,
michael@0 104 directory = PR_FILE_DIRECTORY,
michael@0 105 other = PR_FILE_OTHER
michael@0 106 } FileType;
michael@0 107
michael@0 108 public:
michael@0 109 RCFileInfo();
michael@0 110 RCFileInfo(const RCFileInfo&);
michael@0 111
michael@0 112 virtual ~RCFileInfo();
michael@0 113
michael@0 114 PRInt64 Size() const;
michael@0 115 RCTime CreationTime() const;
michael@0 116 RCTime ModifyTime() const;
michael@0 117 RCFileInfo::FileType Type() const;
michael@0 118
michael@0 119 friend PRStatus RCFileIO::FileInfo(RCFileInfo*) const;
michael@0 120 friend PRStatus RCFileIO::FileInfo(const char *name, RCFileInfo*);
michael@0 121
michael@0 122 private:
michael@0 123 PRFileInfo64 info;
michael@0 124 }; /* RCFileInfo */
michael@0 125
michael@0 126 inline RCFileInfo::RCFileInfo(): RCBase() { }
michael@0 127 inline PRInt64 RCFileInfo::Size() const { return info.size; }
michael@0 128
michael@0 129 #endif /* defined(_RCFILEIO_H) */

mercurial