Back to index

lightning-sunbird  0.9+nobinonly
rcfileio.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039 ** Class definitions for normal and special file I/O (ref: prio.h)
00040 */
00041 
00042 #if defined(_RCFILEIO_H)
00043 #else
00044 #define _RCFILEIO_H
00045 
00046 #include "rcio.h"
00047 #include "rctime.h"
00048 
00049 /*
00050 ** One would normally create a concrete class, such as RCFileIO, but then
00051 ** pass around more generic references, ie., RCIO.
00052 **
00053 ** This subclass of RCIO hides (makes private) the methods that are not
00054 ** applicable to normal files.
00055 */
00056 
00057 class RCFileInfo;
00058 
00059 class PR_IMPLEMENT(RCFileIO): public RCIO
00060 {
00061 public:
00062     RCFileIO();
00063     virtual ~RCFileIO();
00064 
00065     virtual PRInt64     Available();
00066     virtual PRStatus    Close();
00067     static  PRStatus    Delete(const char *name);
00068     virtual PRStatus    FileInfo(RCFileInfo* info) const;
00069     static  PRStatus    FileInfo(const char *name, RCFileInfo* info);
00070     virtual PRStatus    Fsync();
00071     virtual PRStatus    Open(const char *name, PRIntn flags, PRIntn mode);
00072     virtual PRInt32     Read(void *buf, PRSize amount);
00073     virtual PRInt64     Seek(PRInt64 offset, RCIO::Whence how);
00074     virtual PRInt32     Write(const void *buf, PRSize amount);
00075     virtual PRInt32     Writev(
00076                             const PRIOVec *iov, PRSize size,
00077                             const RCInterval& timeout);
00078 
00079 private:
00080 
00081     /* These methods made private are unavailable for this object */
00082     RCFileIO(const RCFileIO&);
00083     void operator=(const RCFileIO&);
00084 
00085     RCIO*       Accept(RCNetAddr* addr, const RCInterval& timeout);
00086     PRInt32     AcceptRead(
00087                     RCIO **newfd, RCNetAddr **address, void *buffer,
00088                     PRSize amount, const RCInterval& timeout);
00089     PRStatus    Bind(const RCNetAddr& addr);
00090     PRStatus    Connect(const RCNetAddr& addr, const RCInterval& timeout);
00091     PRStatus    GetLocalName(RCNetAddr *addr) const;
00092     PRStatus    GetPeerName(RCNetAddr *addr) const;
00093     PRStatus    GetSocketOption(PRSocketOptionData *data) const;
00094     PRStatus    Listen(PRIntn backlog);
00095     PRInt16     Poll(PRInt16 in_flags, PRInt16 *out_flags);
00096     PRInt32     Recv(
00097                     void *buf, PRSize amount, PRIntn flags,
00098                     const RCInterval& timeout);
00099     PRInt32     Recvfrom(
00100                     void *buf, PRSize amount, PRIntn flags,
00101                     RCNetAddr* addr, const RCInterval& timeout);
00102     PRInt32     Send(
00103                     const void *buf, PRSize amount, PRIntn flags,
00104                     const RCInterval& timeout);
00105     PRInt32     Sendto(
00106                     const void *buf, PRSize amount, PRIntn flags,
00107                     const RCNetAddr& addr,
00108                     const RCInterval& timeout);
00109     PRStatus    SetSocketOption(const PRSocketOptionData *data);
00110     PRStatus    Shutdown(RCIO::ShutdownHow how);
00111     PRInt32     TransmitFile(
00112                     RCIO *source, const void *headers,
00113                     PRSize hlen, RCIO::FileDisposition flags,
00114                     const RCInterval& timeout);
00115 public:
00116 
00117     /*
00118     ** The following function return a valid normal file object,
00119     ** Such objects can be used for scanned input and console output.
00120     */
00121     typedef enum {
00122         input = PR_StandardInput,
00123         output = PR_StandardOutput,
00124         error = PR_StandardError
00125     } SpecialFile;
00126 
00127     static RCIO *GetSpecialFile(RCFileIO::SpecialFile special);
00128 
00129 };  /* RCFileIO */
00130 
00131 class PR_IMPLEMENT(RCFileInfo): public RCBase
00132 {
00133 public:
00134     typedef enum {
00135         file = PR_FILE_FILE,
00136         directory = PR_FILE_DIRECTORY,
00137         other = PR_FILE_OTHER
00138     } FileType;
00139 
00140 public:
00141     RCFileInfo();
00142     RCFileInfo(const RCFileInfo&);
00143 
00144     virtual ~RCFileInfo();
00145 
00146     PRInt64 Size() const;
00147     RCTime CreationTime() const;
00148     RCTime ModifyTime() const;
00149     RCFileInfo::FileType Type() const;
00150 
00151 friend PRStatus RCFileIO::FileInfo(RCFileInfo*) const;
00152 friend PRStatus RCFileIO::FileInfo(const char *name, RCFileInfo*);
00153 
00154 private:
00155     PRFileInfo64 info;
00156 };  /* RCFileInfo */
00157 
00158 inline RCFileInfo::RCFileInfo(): RCBase() { }
00159 inline PRInt64 RCFileInfo::Size() const { return info.size; }
00160 
00161 #endif /* defined(_RCFILEIO_H) */