1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 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/
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.
13
* The Original Code is the Netscape Portable Runtime (NSPR).
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
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
36
** Subclass implementation for streamed network I/O (ref: prio.h)
41
#include <private/pprio.h>
43
RCNetStreamIO::~RCNetStreamIO()
44
{ PRStatus rv = (fd->methods->close)(fd); fd = NULL; }
46
RCNetStreamIO::RCNetStreamIO(): RCIO(RCIO::tcp)
47
{ fd = PR_NewTCPSocket(); }
49
RCNetStreamIO::RCNetStreamIO(PRIntn protocol): RCIO(RCIO::tcp)
50
{ fd = PR_Socket(PR_AF_INET, PR_SOCK_STREAM, protocol); }
52
RCIO* RCNetStreamIO::Accept(RCNetAddr* addr, const RCInterval& timeout)
55
RCNetStreamIO* rcio = NULL;
56
PRFileDesc* newfd = fd->methods->accept(fd, &peer, timeout);
59
rcio = new RCNetStreamIO();
66
(void)(newfd->methods->close)(newfd);
69
} /* RCNetStreamIO::Accept */
71
PRInt32 RCNetStreamIO::AcceptRead(
72
RCIO **nd, RCNetAddr **raddr, void *buf,
73
PRSize amount, const RCInterval& timeout)
77
PRInt32 rv = (fd->methods->acceptread)(
78
fd, &accepted, &from, buf, amount, timeout);
81
RCNetStreamIO *ns = new RCNetStreamIO();
82
if (NULL != *nd) ns->fd = accepted;
83
else {PR_Close(accepted); rv = -1; }
87
} /* RCNetStreamIO::AcceptRead */
89
PRInt64 RCNetStreamIO::Available()
90
{ return (fd->methods->available64)(fd); }
92
PRStatus RCNetStreamIO::Bind(const RCNetAddr& addr)
93
{ return (fd->methods->bind)(fd, addr); }
95
PRStatus RCNetStreamIO::Connect(const RCNetAddr& addr, const RCInterval& timeout)
96
{ return (fd->methods->connect)(fd, addr, timeout); }
98
PRStatus RCNetStreamIO::GetLocalName(RCNetAddr *addr) const
101
PRStatus rv = (fd->methods->getsockname)(fd, &local);
102
if (PR_SUCCESS == rv) *addr = &local;
104
} /* RCNetStreamIO::GetLocalName */
106
PRStatus RCNetStreamIO::GetPeerName(RCNetAddr *addr) const
109
PRStatus rv = (fd->methods->getpeername)(fd, &peer);
110
if (PR_SUCCESS == rv) *addr = &peer;
112
} /* RCNetStreamIO::GetPeerName */
114
PRStatus RCNetStreamIO::GetSocketOption(PRSocketOptionData *data) const
115
{ return (fd->methods->getsocketoption)(fd, data); }
117
PRStatus RCNetStreamIO::Listen(PRIntn backlog)
118
{ return (fd->methods->listen)(fd, backlog); }
120
PRInt16 RCNetStreamIO::Poll(PRInt16 in_flags, PRInt16 *out_flags)
121
{ return (fd->methods->poll)(fd, in_flags, out_flags); }
123
PRInt32 RCNetStreamIO::Read(void *buf, PRSize amount)
124
{ return (fd->methods->read)(fd, buf, amount); }
126
PRInt32 RCNetStreamIO::Recv(
127
void *buf, PRSize amount, PRIntn flags, const RCInterval& timeout)
128
{ return (fd->methods->recv)(fd, buf, amount, flags, timeout); }
130
PRInt32 RCNetStreamIO::Recvfrom(
131
void *buf, PRSize amount, PRIntn flags,
132
RCNetAddr* addr, const RCInterval& timeout)
135
PRInt32 rv = (fd->methods->recvfrom)(
136
fd, buf, amount, flags, &peer, timeout);
137
if (-1 != rv) *addr = &peer;
139
} /* RCNetStreamIO::Recvfrom */
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); }
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); }
150
PRStatus RCNetStreamIO::SetSocketOption(const PRSocketOptionData *data)
151
{ return (fd->methods->setsocketoption)(fd, data); }
153
PRStatus RCNetStreamIO::Shutdown(RCIO::ShutdownHow how)
154
{ return (fd->methods->shutdown)(fd, (PRIntn)how); }
156
PRInt32 RCNetStreamIO::TransmitFile(
157
RCIO *source, const void *headers, PRSize hlen,
158
RCIO::FileDisposition flags, const RCInterval& timeout)
160
RCNetStreamIO *src = (RCNetStreamIO*)source;
161
return (fd->methods->transmitfile)(
162
fd, src->fd, headers, hlen, (PRTransmitFileFlags)flags, timeout); }
164
PRInt32 RCNetStreamIO::Write(const void *buf, PRSize amount)
165
{ return (fd->methods->write)(fd, buf, amount); }
167
PRInt32 RCNetStreamIO::Writev(
168
const PRIOVec *iov, PRSize size, const RCInterval& timeout)
169
{ return (fd->methods->writev)(fd, iov, size, timeout); }
175
PRStatus RCNetStreamIO::Close()
176
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
178
PRStatus RCNetStreamIO::FileInfo(RCFileInfo*) const
179
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
181
PRStatus RCNetStreamIO::Fsync()
182
{ return (fd->methods->fsync)(fd); }
184
PRStatus RCNetStreamIO::Open(const char*, PRIntn, PRIntn)
185
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
187
PRInt64 RCNetStreamIO::Seek(PRInt64, RCIO::Whence)
188
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
190
/* RCNetStreamIO.cpp */