Back to index

lightning-sunbird  0.9+nobinonly
rcio.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 ** Base class definitions for I/O (ref: prio.h)
00040 **
00041 ** This class is a virtual base class. Construction must be done by a
00042 ** subclass, but the I/O operations can be done on a RCIO object reference.
00043 */
00044 
00045 #if defined(_RCIO_H)
00046 #else
00047 #define _RCIO_H
00048 
00049 #include "rcbase.h"
00050 #include "rcnetdb.h"
00051 #include "rcinrval.h"
00052 
00053 #include "prio.h"
00054 
00055 class RCFileInfo;
00056 
00057 class PR_IMPLEMENT(RCIO): public RCBase
00058 {
00059 public:
00060     typedef enum {
00061         open = PR_TRANSMITFILE_KEEP_OPEN,   /* socket is left open after file
00062                                              * is transmitted. */
00063         close = PR_TRANSMITFILE_CLOSE_SOCKET/* socket is closed after file
00064                                              * is transmitted. */
00065     } FileDisposition;
00066 
00067     typedef enum {
00068         set = PR_SEEK_SET,                  /* Set to value specified */
00069         current = PR_SEEK_CUR,              /* Seek relative to current position */
00070         end = PR_SEEK_END                   /* seek past end of current eof */
00071     } Whence;
00072 
00073     typedef enum {
00074         recv = PR_SHUTDOWN_RCV,             /* receives will be disallowed */
00075         send = PR_SHUTDOWN_SEND,            /* sends will be disallowed */
00076         both = PR_SHUTDOWN_BOTH             /* sends & receives will be disallowed */
00077     } ShutdownHow;
00078 
00079 public:
00080     virtual ~RCIO();
00081 
00082     virtual RCIO*       Accept(RCNetAddr* addr, const RCInterval& timeout) = 0;
00083     virtual PRInt32     AcceptRead(
00084                             RCIO **nd, RCNetAddr **raddr, void *buf,
00085                             PRSize amount, const RCInterval& timeout) = 0;
00086     virtual PRInt64     Available() = 0;
00087     virtual PRStatus    Bind(const RCNetAddr& addr) = 0;
00088     virtual PRStatus    Close() = 0;
00089     virtual PRStatus    Connect(
00090                             const RCNetAddr& addr,
00091                             const RCInterval& timeout) = 0;
00092     virtual PRStatus    FileInfo(RCFileInfo *info) const = 0;
00093     virtual PRStatus    Fsync() = 0;
00094     virtual PRStatus    GetLocalName(RCNetAddr *addr) const = 0;
00095     virtual PRStatus    GetPeerName(RCNetAddr *addr) const = 0;
00096     virtual PRStatus    GetSocketOption(PRSocketOptionData *data) const = 0;
00097     virtual PRStatus    Listen(PRIntn backlog) = 0;
00098     virtual PRStatus    Open(const char *name, PRIntn flags, PRIntn mode) = 0;
00099     virtual PRInt16     Poll(PRInt16 in_flags, PRInt16 *out_flags) = 0;
00100     virtual PRInt32     Read(void *buf, PRSize amount) = 0;
00101     virtual PRInt32     Recv(
00102                             void *buf, PRSize amount, PRIntn flags,
00103                             const RCInterval& timeout) = 0;
00104     virtual PRInt32     Recvfrom(
00105                             void *buf, PRSize amount, PRIntn flags,
00106                             RCNetAddr* addr, const RCInterval& timeout) = 0;
00107     virtual PRInt64     Seek(PRInt64 offset, Whence how) = 0;
00108     virtual PRInt32     Send(
00109                             const void *buf, PRSize amount, PRIntn flags,
00110                             const RCInterval& timeout) = 0;
00111     virtual PRInt32     Sendto(
00112                             const void *buf, PRSize amount, PRIntn flags,
00113                             const RCNetAddr& addr,
00114                             const RCInterval& timeout) = 0;
00115     virtual PRStatus    SetSocketOption(const PRSocketOptionData *data) = 0;
00116     virtual PRStatus    Shutdown(ShutdownHow how) = 0;
00117     virtual PRInt32     TransmitFile(
00118                             RCIO *source, const void *headers,
00119                             PRSize hlen, RCIO::FileDisposition flags,
00120                             const RCInterval& timeout) = 0;
00121     virtual PRInt32     Write(const void *buf, PRSize amount) = 0;
00122     virtual PRInt32     Writev(
00123                             const PRIOVec *iov, PRSize size,
00124                             const RCInterval& timeout) = 0;
00125 
00126 protected:
00127     typedef enum {
00128         file = PR_DESC_FILE,
00129         tcp = PR_DESC_SOCKET_TCP,
00130         udp = PR_DESC_SOCKET_UDP,
00131         layered = PR_DESC_LAYERED} RCIOType;
00132 
00133     RCIO(RCIOType);
00134 
00135     PRFileDesc *fd;  /* where the real code hides */
00136 
00137 private:
00138     /* no default construction and no copies allowed */
00139     RCIO();
00140     RCIO(const RCIO&);
00141 
00142 };  /* RCIO */
00143 
00144 #endif /* defined(_RCIO_H) */
00145 
00146 /* RCIO.h */
00147 
00148