andre@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ andre@0: andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: #include "primpl.h" andre@0: andre@0: #include andre@0: andre@0: /*****************************************************************************/ andre@0: /************************** Invalid I/O method object ************************/ andre@0: /*****************************************************************************/ andre@0: PRIOMethods _pr_faulty_methods = { andre@0: (PRDescType)0, andre@0: (PRCloseFN)_PR_InvalidStatus, andre@0: (PRReadFN)_PR_InvalidInt, andre@0: (PRWriteFN)_PR_InvalidInt, andre@0: (PRAvailableFN)_PR_InvalidInt, andre@0: (PRAvailable64FN)_PR_InvalidInt64, andre@0: (PRFsyncFN)_PR_InvalidStatus, andre@0: (PRSeekFN)_PR_InvalidInt, andre@0: (PRSeek64FN)_PR_InvalidInt64, andre@0: (PRFileInfoFN)_PR_InvalidStatus, andre@0: (PRFileInfo64FN)_PR_InvalidStatus, andre@0: (PRWritevFN)_PR_InvalidInt, andre@0: (PRConnectFN)_PR_InvalidStatus, andre@0: (PRAcceptFN)_PR_InvalidDesc, andre@0: (PRBindFN)_PR_InvalidStatus, andre@0: (PRListenFN)_PR_InvalidStatus, andre@0: (PRShutdownFN)_PR_InvalidStatus, andre@0: (PRRecvFN)_PR_InvalidInt, andre@0: (PRSendFN)_PR_InvalidInt, andre@0: (PRRecvfromFN)_PR_InvalidInt, andre@0: (PRSendtoFN)_PR_InvalidInt, andre@0: (PRPollFN)_PR_InvalidInt16, andre@0: (PRAcceptreadFN)_PR_InvalidInt, andre@0: (PRTransmitfileFN)_PR_InvalidInt, andre@0: (PRGetsocknameFN)_PR_InvalidStatus, andre@0: (PRGetpeernameFN)_PR_InvalidStatus, andre@0: (PRReservedFN)_PR_InvalidInt, andre@0: (PRReservedFN)_PR_InvalidInt, andre@0: (PRGetsocketoptionFN)_PR_InvalidStatus, andre@0: (PRSetsocketoptionFN)_PR_InvalidStatus, andre@0: (PRSendfileFN)_PR_InvalidInt, andre@0: (PRConnectcontinueFN)_PR_InvalidStatus, andre@0: (PRReservedFN)_PR_InvalidInt, andre@0: (PRReservedFN)_PR_InvalidInt, andre@0: (PRReservedFN)_PR_InvalidInt, andre@0: (PRReservedFN)_PR_InvalidInt andre@0: }; andre@0: andre@0: PRIntn _PR_InvalidInt(void) andre@0: { andre@0: PR_ASSERT(!"I/O method is invalid"); andre@0: PR_SetError(PR_INVALID_METHOD_ERROR, 0); andre@0: return -1; andre@0: } /* _PR_InvalidInt */ andre@0: andre@0: PRInt16 _PR_InvalidInt16(void) andre@0: { andre@0: PR_ASSERT(!"I/O method is invalid"); andre@0: PR_SetError(PR_INVALID_METHOD_ERROR, 0); andre@0: return -1; andre@0: } /* _PR_InvalidInt */ andre@0: andre@0: PRInt64 _PR_InvalidInt64(void) andre@0: { andre@0: PRInt64 rv; andre@0: LL_I2L(rv, -1); andre@0: PR_ASSERT(!"I/O method is invalid"); andre@0: PR_SetError(PR_INVALID_METHOD_ERROR, 0); andre@0: return rv; andre@0: } /* _PR_InvalidInt */ andre@0: andre@0: /* andre@0: * An invalid method that returns PRStatus andre@0: */ andre@0: andre@0: PRStatus _PR_InvalidStatus(void) andre@0: { andre@0: PR_ASSERT(!"I/O method is invalid"); andre@0: PR_SetError(PR_INVALID_METHOD_ERROR, 0); andre@0: return PR_FAILURE; andre@0: } /* _PR_InvalidDesc */ andre@0: andre@0: /* andre@0: * An invalid method that returns a pointer andre@0: */ andre@0: andre@0: PRFileDesc *_PR_InvalidDesc(void) andre@0: { andre@0: PR_ASSERT(!"I/O method is invalid"); andre@0: PR_SetError(PR_INVALID_METHOD_ERROR, 0); andre@0: return NULL; andre@0: } /* _PR_InvalidDesc */ andre@0: andre@0: PR_IMPLEMENT(PRDescType) PR_GetDescType(PRFileDesc *file) andre@0: { andre@0: return file->methods->file_type; andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_Close(PRFileDesc *fd) andre@0: { andre@0: return (fd->methods->close)(fd); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_Read(PRFileDesc *fd, void *buf, PRInt32 amount) andre@0: { andre@0: return((fd->methods->read)(fd,buf,amount)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_Write(PRFileDesc *fd, const void *buf, PRInt32 amount) andre@0: { andre@0: return((fd->methods->write)(fd,buf,amount)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_Seek(PRFileDesc *fd, PRInt32 offset, PRSeekWhence whence) andre@0: { andre@0: return((fd->methods->seek)(fd, offset, whence)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt64) PR_Seek64(PRFileDesc *fd, PRInt64 offset, PRSeekWhence whence) andre@0: { andre@0: return((fd->methods->seek64)(fd, offset, whence)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_Available(PRFileDesc *fd) andre@0: { andre@0: return((fd->methods->available)(fd)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt64) PR_Available64(PRFileDesc *fd) andre@0: { andre@0: return((fd->methods->available64)(fd)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_GetOpenFileInfo(PRFileDesc *fd, PRFileInfo *info) andre@0: { andre@0: return((fd->methods->fileInfo)(fd, info)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_GetOpenFileInfo64(PRFileDesc *fd, PRFileInfo64 *info) andre@0: { andre@0: return((fd->methods->fileInfo64)(fd, info)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_Sync(PRFileDesc *fd) andre@0: { andre@0: return((fd->methods->fsync)(fd)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_Connect( andre@0: PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout) andre@0: { andre@0: return((fd->methods->connect)(fd,addr,timeout)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_ConnectContinue( andre@0: PRFileDesc *fd, PRInt16 out_flags) andre@0: { andre@0: return((fd->methods->connectcontinue)(fd,out_flags)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRFileDesc*) PR_Accept(PRFileDesc *fd, PRNetAddr *addr, andre@0: PRIntervalTime timeout) andre@0: { andre@0: return((fd->methods->accept)(fd,addr,timeout)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_Bind(PRFileDesc *fd, const PRNetAddr *addr) andre@0: { andre@0: return((fd->methods->bind)(fd,addr)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_Shutdown(PRFileDesc *fd, PRShutdownHow how) andre@0: { andre@0: return((fd->methods->shutdown)(fd,how)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_Listen(PRFileDesc *fd, PRIntn backlog) andre@0: { andre@0: return((fd->methods->listen)(fd,backlog)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_Recv(PRFileDesc *fd, void *buf, PRInt32 amount, andre@0: PRIntn flags, PRIntervalTime timeout) andre@0: { andre@0: return((fd->methods->recv)(fd,buf,amount,flags,timeout)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_Send(PRFileDesc *fd, const void *buf, PRInt32 amount, andre@0: PRIntn flags, PRIntervalTime timeout) andre@0: { andre@0: return((fd->methods->send)(fd,buf,amount,flags,timeout)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_Writev(PRFileDesc *fd, const PRIOVec *iov, andre@0: PRInt32 iov_size, PRIntervalTime timeout) andre@0: { andre@0: if (iov_size > PR_MAX_IOVECTOR_SIZE) andre@0: { andre@0: PR_SetError(PR_BUFFER_OVERFLOW_ERROR, 0); andre@0: return -1; andre@0: } andre@0: return((fd->methods->writev)(fd,iov,iov_size,timeout)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_RecvFrom(PRFileDesc *fd, void *buf, PRInt32 amount, andre@0: PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout) andre@0: { andre@0: return((fd->methods->recvfrom)(fd,buf,amount,flags,addr,timeout)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_SendTo( andre@0: PRFileDesc *fd, const void *buf, PRInt32 amount, andre@0: PRIntn flags, const PRNetAddr *addr, PRIntervalTime timeout) andre@0: { andre@0: return((fd->methods->sendto)(fd,buf,amount,flags,addr,timeout)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_TransmitFile( andre@0: PRFileDesc *sd, PRFileDesc *fd, const void *hdr, PRInt32 hlen, andre@0: PRTransmitFileFlags flags, PRIntervalTime timeout) andre@0: { andre@0: return((sd->methods->transmitfile)(sd,fd,hdr,hlen,flags,timeout)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_AcceptRead( andre@0: PRFileDesc *sd, PRFileDesc **nd, PRNetAddr **raddr, andre@0: void *buf, PRInt32 amount, PRIntervalTime timeout) andre@0: { andre@0: return((sd->methods->acceptread)(sd, nd, raddr, buf, amount,timeout)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_GetSockName(PRFileDesc *fd, PRNetAddr *addr) andre@0: { andre@0: return((fd->methods->getsockname)(fd,addr)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_GetPeerName(PRFileDesc *fd, PRNetAddr *addr) andre@0: { andre@0: return((fd->methods->getpeername)(fd,addr)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_GetSocketOption( andre@0: PRFileDesc *fd, PRSocketOptionData *data) andre@0: { andre@0: return((fd->methods->getsocketoption)(fd, data)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRStatus) PR_SetSocketOption( andre@0: PRFileDesc *fd, const PRSocketOptionData *data) andre@0: { andre@0: return((fd->methods->setsocketoption)(fd, data)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_SendFile( andre@0: PRFileDesc *sd, PRSendFileData *sfd, andre@0: PRTransmitFileFlags flags, PRIntervalTime timeout) andre@0: { andre@0: return((sd->methods->sendfile)(sd,sfd,flags,timeout)); andre@0: } andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_EmulateAcceptRead( andre@0: PRFileDesc *sd, PRFileDesc **nd, PRNetAddr **raddr, andre@0: void *buf, PRInt32 amount, PRIntervalTime timeout) andre@0: { andre@0: PRInt32 rv = -1; andre@0: PRNetAddr remote; andre@0: PRFileDesc *accepted = NULL; andre@0: andre@0: /* andre@0: ** The timeout does not apply to the accept portion of the andre@0: ** operation - it waits indefinitely. andre@0: */ andre@0: accepted = PR_Accept(sd, &remote, PR_INTERVAL_NO_TIMEOUT); andre@0: if (NULL == accepted) return rv; andre@0: andre@0: rv = PR_Recv(accepted, buf, amount, 0, timeout); andre@0: if (rv >= 0) andre@0: { andre@0: /* copy the new info out where caller can see it */ andre@0: #define AMASK ((PRPtrdiff)7) /* mask for alignment of PRNetAddr */ andre@0: PRPtrdiff aligned = (PRPtrdiff)buf + amount + AMASK; andre@0: *raddr = (PRNetAddr*)(aligned & ~AMASK); andre@0: memcpy(*raddr, &remote, PR_NETADDR_SIZE(&remote)); andre@0: *nd = accepted; andre@0: return rv; andre@0: } andre@0: andre@0: PR_Close(accepted); andre@0: return rv; andre@0: } andre@0: andre@0: /* andre@0: * PR_EmulateSendFile andre@0: * andre@0: * Send file sfd->fd across socket sd. If header/trailer are specified andre@0: * they are sent before and after the file, respectively. andre@0: * andre@0: * PR_TRANSMITFILE_CLOSE_SOCKET flag - close socket after sending file andre@0: * andre@0: * return number of bytes sent or -1 on error andre@0: * andre@0: */ andre@0: andre@0: #if defined(XP_UNIX) || defined(WIN32) andre@0: andre@0: /* andre@0: * An implementation based on memory-mapped files andre@0: */ andre@0: andre@0: #define SENDFILE_MMAP_CHUNK (256 * 1024) andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_EmulateSendFile( andre@0: PRFileDesc *sd, PRSendFileData *sfd, andre@0: PRTransmitFileFlags flags, PRIntervalTime timeout) andre@0: { andre@0: PRInt32 rv, count = 0; andre@0: PRInt32 len, file_bytes, index = 0; andre@0: PRFileInfo info; andre@0: PRIOVec iov[3]; andre@0: PRFileMap *mapHandle = NULL; andre@0: void *addr = (void*)0; /* initialized to some arbitrary value. Keeps compiler warnings down. */ andre@0: PRUint32 file_mmap_offset, alignment; andre@0: PRInt64 zero64; andre@0: PROffset64 file_mmap_offset64; andre@0: PRUint32 addr_offset, mmap_len; andre@0: andre@0: /* Get file size */ andre@0: if (PR_SUCCESS != PR_GetOpenFileInfo(sfd->fd, &info)) { andre@0: count = -1; andre@0: goto done; andre@0: } andre@0: if (sfd->file_nbytes && andre@0: (info.size < (sfd->file_offset + sfd->file_nbytes))) { andre@0: /* andre@0: * there are fewer bytes in file to send than specified andre@0: */ andre@0: PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); andre@0: count = -1; andre@0: goto done; andre@0: } andre@0: if (sfd->file_nbytes) andre@0: file_bytes = sfd->file_nbytes; andre@0: else andre@0: file_bytes = info.size - sfd->file_offset; andre@0: andre@0: alignment = PR_GetMemMapAlignment(); andre@0: andre@0: /* number of initial bytes to skip in mmap'd segment */ andre@0: addr_offset = sfd->file_offset % alignment; andre@0: andre@0: /* find previous mmap alignment boundary */ andre@0: file_mmap_offset = sfd->file_offset - addr_offset; andre@0: andre@0: /* andre@0: * If the file is large, mmap and send the file in chunks so as andre@0: * to not consume too much virtual address space andre@0: */ andre@0: mmap_len = PR_MIN(file_bytes + addr_offset, SENDFILE_MMAP_CHUNK); andre@0: len = mmap_len - addr_offset; andre@0: andre@0: /* andre@0: * Map in (part of) file. Take care of zero-length files. andre@0: */ andre@0: if (len) { andre@0: LL_I2L(zero64, 0); andre@0: mapHandle = PR_CreateFileMap(sfd->fd, zero64, PR_PROT_READONLY); andre@0: if (!mapHandle) { andre@0: count = -1; andre@0: goto done; andre@0: } andre@0: LL_I2L(file_mmap_offset64, file_mmap_offset); andre@0: addr = PR_MemMap(mapHandle, file_mmap_offset64, mmap_len); andre@0: if (!addr) { andre@0: count = -1; andre@0: goto done; andre@0: } andre@0: } andre@0: /* andre@0: * send headers first, followed by the file andre@0: */ andre@0: if (sfd->hlen) { andre@0: iov[index].iov_base = (char *) sfd->header; andre@0: iov[index].iov_len = sfd->hlen; andre@0: index++; andre@0: } andre@0: if (len) { andre@0: iov[index].iov_base = (char*)addr + addr_offset; andre@0: iov[index].iov_len = len; andre@0: index++; andre@0: } andre@0: if ((file_bytes == len) && (sfd->tlen)) { andre@0: /* andre@0: * all file data is mapped in; send the trailer too andre@0: */ andre@0: iov[index].iov_base = (char *) sfd->trailer; andre@0: iov[index].iov_len = sfd->tlen; andre@0: index++; andre@0: } andre@0: rv = PR_Writev(sd, iov, index, timeout); andre@0: if (len) andre@0: PR_MemUnmap(addr, mmap_len); andre@0: if (rv < 0) { andre@0: count = -1; andre@0: goto done; andre@0: } andre@0: andre@0: PR_ASSERT(rv == sfd->hlen + len + ((len == file_bytes) ? sfd->tlen : 0)); andre@0: andre@0: file_bytes -= len; andre@0: count += rv; andre@0: if (!file_bytes) /* header, file and trailer are sent */ andre@0: goto done; andre@0: andre@0: /* andre@0: * send remaining bytes of the file, if any andre@0: */ andre@0: len = PR_MIN(file_bytes, SENDFILE_MMAP_CHUNK); andre@0: while (len > 0) { andre@0: /* andre@0: * Map in (part of) file andre@0: */ andre@0: file_mmap_offset = sfd->file_offset + count - sfd->hlen; andre@0: PR_ASSERT((file_mmap_offset % alignment) == 0); andre@0: andre@0: LL_I2L(file_mmap_offset64, file_mmap_offset); andre@0: addr = PR_MemMap(mapHandle, file_mmap_offset64, len); andre@0: if (!addr) { andre@0: count = -1; andre@0: goto done; andre@0: } andre@0: rv = PR_Send(sd, addr, len, 0, timeout); andre@0: PR_MemUnmap(addr, len); andre@0: if (rv < 0) { andre@0: count = -1; andre@0: goto done; andre@0: } andre@0: andre@0: PR_ASSERT(rv == len); andre@0: file_bytes -= rv; andre@0: count += rv; andre@0: len = PR_MIN(file_bytes, SENDFILE_MMAP_CHUNK); andre@0: } andre@0: PR_ASSERT(0 == file_bytes); andre@0: if (sfd->tlen) { andre@0: rv = PR_Send(sd, sfd->trailer, sfd->tlen, 0, timeout); andre@0: if (rv >= 0) { andre@0: PR_ASSERT(rv == sfd->tlen); andre@0: count += rv; andre@0: } else andre@0: count = -1; andre@0: } andre@0: done: andre@0: if (mapHandle) andre@0: PR_CloseFileMap(mapHandle); andre@0: if ((count >= 0) && (flags & PR_TRANSMITFILE_CLOSE_SOCKET)) andre@0: PR_Close(sd); andre@0: return count; andre@0: } andre@0: andre@0: #else andre@0: andre@0: PR_IMPLEMENT(PRInt32) PR_EmulateSendFile( andre@0: PRFileDesc *sd, PRSendFileData *sfd, andre@0: PRTransmitFileFlags flags, PRIntervalTime timeout) andre@0: { andre@0: PRInt32 rv, count = 0; andre@0: PRInt32 rlen; andre@0: const void * buffer; andre@0: PRInt32 buflen; andre@0: PRInt32 sendbytes, readbytes; andre@0: char *buf; andre@0: andre@0: #define _SENDFILE_BUFSIZE (16 * 1024) andre@0: andre@0: buf = (char*)PR_MALLOC(_SENDFILE_BUFSIZE); andre@0: if (buf == NULL) { andre@0: PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); andre@0: return -1; andre@0: } andre@0: andre@0: /* andre@0: * send header first andre@0: */ andre@0: buflen = sfd->hlen; andre@0: buffer = sfd->header; andre@0: while (buflen) { andre@0: rv = PR_Send(sd, buffer, buflen, 0, timeout); andre@0: if (rv < 0) { andre@0: /* PR_Send() has invoked PR_SetError(). */ andre@0: rv = -1; andre@0: goto done; andre@0: } else { andre@0: count += rv; andre@0: buffer = (const void*) ((const char*)buffer + rv); andre@0: buflen -= rv; andre@0: } andre@0: } andre@0: andre@0: /* andre@0: * send file next andre@0: */ andre@0: if (PR_Seek(sfd->fd, sfd->file_offset, PR_SEEK_SET) < 0) { andre@0: rv = -1; andre@0: goto done; andre@0: } andre@0: sendbytes = sfd->file_nbytes; andre@0: if (sendbytes == 0) { andre@0: /* send entire file */ andre@0: while ((rlen = PR_Read(sfd->fd, buf, _SENDFILE_BUFSIZE)) > 0) { andre@0: while (rlen) { andre@0: char *bufptr = buf; andre@0: andre@0: rv = PR_Send(sd, bufptr, rlen, 0, timeout); andre@0: if (rv < 0) { andre@0: /* PR_Send() has invoked PR_SetError(). */ andre@0: rv = -1; andre@0: goto done; andre@0: } else { andre@0: count += rv; andre@0: bufptr = ((char*)bufptr + rv); andre@0: rlen -= rv; andre@0: } andre@0: } andre@0: } andre@0: if (rlen < 0) { andre@0: /* PR_Read() has invoked PR_SetError(). */ andre@0: rv = -1; andre@0: goto done; andre@0: } andre@0: } else { andre@0: readbytes = PR_MIN(sendbytes, _SENDFILE_BUFSIZE); andre@0: while (readbytes && ((rlen = PR_Read(sfd->fd, buf, readbytes)) > 0)) { andre@0: while (rlen) { andre@0: char *bufptr = buf; andre@0: andre@0: rv = PR_Send(sd, bufptr, rlen, 0, timeout); andre@0: if (rv < 0) { andre@0: /* PR_Send() has invoked PR_SetError(). */ andre@0: rv = -1; andre@0: goto done; andre@0: } else { andre@0: count += rv; andre@0: sendbytes -= rv; andre@0: bufptr = ((char*)bufptr + rv); andre@0: rlen -= rv; andre@0: } andre@0: } andre@0: readbytes = PR_MIN(sendbytes, _SENDFILE_BUFSIZE); andre@0: } andre@0: if (rlen < 0) { andre@0: /* PR_Read() has invoked PR_SetError(). */ andre@0: rv = -1; andre@0: goto done; andre@0: } else if (sendbytes != 0) { andre@0: /* andre@0: * there are fewer bytes in file to send than specified andre@0: */ andre@0: PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); andre@0: rv = -1; andre@0: goto done; andre@0: } andre@0: } andre@0: andre@0: /* andre@0: * send trailer last andre@0: */ andre@0: buflen = sfd->tlen; andre@0: buffer = sfd->trailer; andre@0: while (buflen) { andre@0: rv = PR_Send(sd, buffer, buflen, 0, timeout); andre@0: if (rv < 0) { andre@0: /* PR_Send() has invoked PR_SetError(). */ andre@0: rv = -1; andre@0: goto done; andre@0: } else { andre@0: count += rv; andre@0: buffer = (const void*) ((const char*)buffer + rv); andre@0: buflen -= rv; andre@0: } andre@0: } andre@0: rv = count; andre@0: andre@0: done: andre@0: if (buf) andre@0: PR_DELETE(buf); andre@0: if ((rv >= 0) && (flags & PR_TRANSMITFILE_CLOSE_SOCKET)) andre@0: PR_Close(sd); andre@0: return rv; andre@0: } andre@0: andre@0: #endif andre@0: andre@0: /* priometh.c */