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