michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: ** Class definitions for normal and special file I/O (ref: prio.h) michael@0: */ michael@0: michael@0: #if defined(_RCFILEIO_H) michael@0: #else michael@0: #define _RCFILEIO_H michael@0: michael@0: #include "rcio.h" michael@0: #include "rctime.h" michael@0: michael@0: /* michael@0: ** One would normally create a concrete class, such as RCFileIO, but then michael@0: ** pass around more generic references, ie., RCIO. michael@0: ** michael@0: ** This subclass of RCIO hides (makes private) the methods that are not michael@0: ** applicable to normal files. michael@0: */ michael@0: michael@0: class RCFileInfo; michael@0: michael@0: class PR_IMPLEMENT(RCFileIO): public RCIO michael@0: { michael@0: public: michael@0: RCFileIO(); michael@0: virtual ~RCFileIO(); michael@0: michael@0: virtual PRInt64 Available(); michael@0: virtual PRStatus Close(); michael@0: static PRStatus Delete(const char *name); michael@0: virtual PRStatus FileInfo(RCFileInfo* info) const; michael@0: static PRStatus FileInfo(const char *name, RCFileInfo* info); michael@0: virtual PRStatus Fsync(); michael@0: virtual PRStatus Open(const char *name, PRIntn flags, PRIntn mode); michael@0: virtual PRInt32 Read(void *buf, PRSize amount); michael@0: virtual PRInt64 Seek(PRInt64 offset, RCIO::Whence how); michael@0: virtual PRInt32 Write(const void *buf, PRSize amount); michael@0: virtual PRInt32 Writev( michael@0: const PRIOVec *iov, PRSize size, michael@0: const RCInterval& timeout); michael@0: michael@0: private: michael@0: michael@0: /* These methods made private are unavailable for this object */ michael@0: RCFileIO(const RCFileIO&); michael@0: void operator=(const RCFileIO&); michael@0: michael@0: RCIO* Accept(RCNetAddr* addr, const RCInterval& timeout); michael@0: PRInt32 AcceptRead( michael@0: RCIO **newfd, RCNetAddr **address, void *buffer, michael@0: PRSize amount, const RCInterval& timeout); michael@0: PRStatus Bind(const RCNetAddr& addr); michael@0: PRStatus Connect(const RCNetAddr& addr, const RCInterval& timeout); michael@0: PRStatus GetLocalName(RCNetAddr *addr) const; michael@0: PRStatus GetPeerName(RCNetAddr *addr) const; michael@0: PRStatus GetSocketOption(PRSocketOptionData *data) const; michael@0: PRStatus Listen(PRIntn backlog); michael@0: PRInt16 Poll(PRInt16 in_flags, PRInt16 *out_flags); michael@0: PRInt32 Recv( michael@0: void *buf, PRSize amount, PRIntn flags, michael@0: const RCInterval& timeout); michael@0: PRInt32 Recvfrom( michael@0: void *buf, PRSize amount, PRIntn flags, michael@0: RCNetAddr* addr, const RCInterval& timeout); michael@0: PRInt32 Send( michael@0: const void *buf, PRSize amount, PRIntn flags, michael@0: const RCInterval& timeout); michael@0: PRInt32 Sendto( michael@0: const void *buf, PRSize amount, PRIntn flags, michael@0: const RCNetAddr& addr, michael@0: const RCInterval& timeout); michael@0: PRStatus SetSocketOption(const PRSocketOptionData *data); michael@0: PRStatus Shutdown(RCIO::ShutdownHow how); michael@0: PRInt32 TransmitFile( michael@0: RCIO *source, const void *headers, michael@0: PRSize hlen, RCIO::FileDisposition flags, michael@0: const RCInterval& timeout); michael@0: public: michael@0: michael@0: /* michael@0: ** The following function return a valid normal file object, michael@0: ** Such objects can be used for scanned input and console output. michael@0: */ michael@0: typedef enum { michael@0: input = PR_StandardInput, michael@0: output = PR_StandardOutput, michael@0: error = PR_StandardError michael@0: } SpecialFile; michael@0: michael@0: static RCIO *GetSpecialFile(RCFileIO::SpecialFile special); michael@0: michael@0: }; /* RCFileIO */ michael@0: michael@0: class PR_IMPLEMENT(RCFileInfo): public RCBase michael@0: { michael@0: public: michael@0: typedef enum { michael@0: file = PR_FILE_FILE, michael@0: directory = PR_FILE_DIRECTORY, michael@0: other = PR_FILE_OTHER michael@0: } FileType; michael@0: michael@0: public: michael@0: RCFileInfo(); michael@0: RCFileInfo(const RCFileInfo&); michael@0: michael@0: virtual ~RCFileInfo(); michael@0: michael@0: PRInt64 Size() const; michael@0: RCTime CreationTime() const; michael@0: RCTime ModifyTime() const; michael@0: RCFileInfo::FileType Type() const; michael@0: michael@0: friend PRStatus RCFileIO::FileInfo(RCFileInfo*) const; michael@0: friend PRStatus RCFileIO::FileInfo(const char *name, RCFileInfo*); michael@0: michael@0: private: michael@0: PRFileInfo64 info; michael@0: }; /* RCFileInfo */ michael@0: michael@0: inline RCFileInfo::RCFileInfo(): RCBase() { } michael@0: inline PRInt64 RCFileInfo::Size() const { return info.size; } michael@0: michael@0: #endif /* defined(_RCFILEIO_H) */