~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/nsprpub/pr/src/cplus/rcnetio.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/* 
 
3
 * The contents of this file are subject to the Mozilla Public
 
4
 * License Version 1.1 (the "License"); you may not use this file
 
5
 * except in compliance with the License. You may obtain a copy of
 
6
 * the License at http://www.mozilla.org/MPL/
 
7
 * 
 
8
 * Software distributed under the License is distributed on an "AS
 
9
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
 * implied. See the License for the specific language governing
 
11
 * rights and limitations under the License.
 
12
 * 
 
13
 * The Original Code is the Netscape Portable Runtime (NSPR).
 
14
 * 
 
15
 * The Initial Developer of the Original Code is Netscape
 
16
 * Communications Corporation.  Portions created by Netscape are 
 
17
 * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
 
18
 * Rights Reserved.
 
19
 * 
 
20
 * Contributor(s):
 
21
 * 
 
22
 * Alternatively, the contents of this file may be used under the
 
23
 * terms of the GNU General Public License Version 2 or later (the
 
24
 * "GPL"), in which case the provisions of the GPL are applicable 
 
25
 * instead of those above.  If you wish to allow use of your 
 
26
 * version of this file only under the terms of the GPL and not to
 
27
 * allow others to use your version of this file under the MPL,
 
28
 * indicate your decision by deleting the provisions above and
 
29
 * replace them with the notice and other provisions required by
 
30
 * the GPL.  If you do not delete the provisions above, a recipient
 
31
 * may use your version of this file under either the MPL or the
 
32
 * GPL.
 
33
 */
 
34
 
 
35
/*
 
36
** Subclass implementation for streamed network I/O (ref: prio.h)
 
37
*/
 
38
 
 
39
#include "rcnetio.h"
 
40
 
 
41
#include <private/pprio.h>
 
42
 
 
43
RCNetStreamIO::~RCNetStreamIO()
 
44
    { PRStatus rv = (fd->methods->close)(fd); fd = NULL; }
 
45
 
 
46
RCNetStreamIO::RCNetStreamIO(): RCIO(RCIO::tcp)
 
47
    { fd = PR_NewTCPSocket(); }
 
48
 
 
49
RCNetStreamIO::RCNetStreamIO(PRIntn protocol): RCIO(RCIO::tcp)
 
50
    { fd = PR_Socket(PR_AF_INET, PR_SOCK_STREAM, protocol); }
 
51
 
 
52
RCIO* RCNetStreamIO::Accept(RCNetAddr* addr, const RCInterval& timeout)
 
53
{
 
54
    PRNetAddr peer;
 
55
    RCNetStreamIO* rcio = NULL;
 
56
    PRFileDesc* newfd = fd->methods->accept(fd, &peer, timeout);
 
57
    if (NULL != newfd)
 
58
    {
 
59
        rcio = new RCNetStreamIO();
 
60
        if (NULL != rcio)
 
61
        {
 
62
            *addr = &peer;
 
63
            rcio->fd = newfd;
 
64
        }
 
65
        else
 
66
            (void)(newfd->methods->close)(newfd);
 
67
    }
 
68
    return rcio;
 
69
}  /* RCNetStreamIO::Accept */
 
70
 
 
71
PRInt32 RCNetStreamIO::AcceptRead(
 
72
    RCIO **nd, RCNetAddr **raddr, void *buf,
 
73
    PRSize amount, const RCInterval& timeout)
 
74
{   
 
75
    PRNetAddr *from;
 
76
    PRFileDesc *accepted;
 
77
    PRInt32 rv = (fd->methods->acceptread)(
 
78
        fd, &accepted, &from, buf, amount, timeout);
 
79
    if (rv >= 0)
 
80
    {
 
81
        RCNetStreamIO *ns = new RCNetStreamIO();
 
82
        if (NULL != *nd) ns->fd = accepted;
 
83
        else {PR_Close(accepted); rv = -1; }
 
84
        *nd = ns;
 
85
    }
 
86
    return rv;
 
87
}  /* RCNetStreamIO::AcceptRead */
 
88
 
 
89
PRInt64 RCNetStreamIO::Available()
 
90
    { return (fd->methods->available64)(fd); }
 
91
 
 
92
PRStatus RCNetStreamIO::Bind(const RCNetAddr& addr)
 
93
    { return (fd->methods->bind)(fd, addr); }
 
94
 
 
95
PRStatus RCNetStreamIO::Connect(const RCNetAddr& addr, const RCInterval& timeout)
 
96
    { return (fd->methods->connect)(fd, addr, timeout); }
 
97
 
 
98
PRStatus RCNetStreamIO::GetLocalName(RCNetAddr *addr) const
 
99
{
 
100
    PRNetAddr local;
 
101
    PRStatus rv = (fd->methods->getsockname)(fd, &local);
 
102
    if (PR_SUCCESS == rv) *addr = &local;
 
103
    return rv;
 
104
}  /* RCNetStreamIO::GetLocalName */
 
105
 
 
106
PRStatus RCNetStreamIO::GetPeerName(RCNetAddr *addr) const
 
107
{
 
108
    PRNetAddr peer;
 
109
    PRStatus rv = (fd->methods->getpeername)(fd, &peer);
 
110
    if (PR_SUCCESS == rv) *addr = &peer;
 
111
    return rv;
 
112
}  /* RCNetStreamIO::GetPeerName */
 
113
 
 
114
PRStatus RCNetStreamIO::GetSocketOption(PRSocketOptionData *data) const
 
115
    { return (fd->methods->getsocketoption)(fd, data); }
 
116
 
 
117
PRStatus RCNetStreamIO::Listen(PRIntn backlog)
 
118
    { return (fd->methods->listen)(fd, backlog); }
 
119
 
 
120
PRInt16 RCNetStreamIO::Poll(PRInt16 in_flags, PRInt16 *out_flags)
 
121
    { return (fd->methods->poll)(fd, in_flags, out_flags); }
 
122
 
 
123
PRInt32 RCNetStreamIO::Read(void *buf, PRSize amount)
 
124
    { return (fd->methods->read)(fd, buf, amount); }
 
125
 
 
126
PRInt32 RCNetStreamIO::Recv(
 
127
    void *buf, PRSize amount, PRIntn flags, const RCInterval& timeout)
 
128
    { return (fd->methods->recv)(fd, buf, amount, flags, timeout); }
 
129
 
 
130
PRInt32 RCNetStreamIO::Recvfrom(
 
131
    void *buf, PRSize amount, PRIntn flags,
 
132
    RCNetAddr* addr, const RCInterval& timeout)
 
133
{
 
134
    PRNetAddr peer;
 
135
    PRInt32 rv = (fd->methods->recvfrom)(
 
136
        fd, buf, amount, flags, &peer, timeout);
 
137
    if (-1 != rv) *addr = &peer;
 
138
    return rv;
 
139
}  /* RCNetStreamIO::Recvfrom */
 
140
 
 
141
PRInt32 RCNetStreamIO::Send(
 
142
    const void *buf, PRSize amount, PRIntn flags, const RCInterval& timeout)
 
143
    { return (fd->methods->send)(fd, buf, amount, flags, timeout); }
 
144
 
 
145
PRInt32 RCNetStreamIO::Sendto(
 
146
    const void *buf, PRSize amount, PRIntn flags,
 
147
    const RCNetAddr& addr, const RCInterval& timeout)
 
148
    { return (fd->methods->sendto)(fd, buf, amount, flags, addr, timeout); }
 
149
 
 
150
PRStatus RCNetStreamIO::SetSocketOption(const PRSocketOptionData *data)
 
151
    { return (fd->methods->setsocketoption)(fd, data); }
 
152
 
 
153
PRStatus RCNetStreamIO::Shutdown(RCIO::ShutdownHow how)
 
154
    { return (fd->methods->shutdown)(fd, (PRIntn)how); }
 
155
 
 
156
PRInt32 RCNetStreamIO::TransmitFile(
 
157
    RCIO *source, const void *headers, PRSize hlen,
 
158
    RCIO::FileDisposition flags, const RCInterval& timeout)
 
159
{
 
160
    RCNetStreamIO *src = (RCNetStreamIO*)source;
 
161
    return (fd->methods->transmitfile)(
 
162
        fd, src->fd, headers, hlen, (PRTransmitFileFlags)flags, timeout); }
 
163
 
 
164
PRInt32 RCNetStreamIO::Write(const void *buf, PRSize amount)
 
165
    { return (fd->methods->write)(fd, buf, amount); }
 
166
 
 
167
PRInt32 RCNetStreamIO::Writev(
 
168
    const PRIOVec *iov, PRSize size, const RCInterval& timeout)
 
169
    { return (fd->methods->writev)(fd, iov, size, timeout); }
 
170
    
 
171
/*
 
172
** Invalid functions
 
173
*/
 
174
 
 
175
PRStatus RCNetStreamIO::Close()
 
176
    { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
 
177
 
 
178
PRStatus RCNetStreamIO::FileInfo(RCFileInfo*) const
 
179
    { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
 
180
 
 
181
PRStatus RCNetStreamIO::Fsync()
 
182
    { return (fd->methods->fsync)(fd); }
 
183
 
 
184
PRStatus RCNetStreamIO::Open(const char*, PRIntn, PRIntn)
 
185
    { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
 
186
 
 
187
PRInt64 RCNetStreamIO::Seek(PRInt64, RCIO::Whence)
 
188
    { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
 
189
 
 
190
/* RCNetStreamIO.cpp */
 
191
 
 
192