diff options
Diffstat (limited to 'nsprpub/pr/src/io/priometh.c')
-rw-r--r-- | nsprpub/pr/src/io/priometh.c | 139 |
1 files changed, 75 insertions, 64 deletions
diff --git a/nsprpub/pr/src/io/priometh.c b/nsprpub/pr/src/io/priometh.c index 4208767d5..508719a80 100644 --- a/nsprpub/pr/src/io/priometh.c +++ b/nsprpub/pr/src/io/priometh.c @@ -22,26 +22,26 @@ PRIOMethods _pr_faulty_methods = { (PRSeek64FN)_PR_InvalidInt64, (PRFileInfoFN)_PR_InvalidStatus, (PRFileInfo64FN)_PR_InvalidStatus, - (PRWritevFN)_PR_InvalidInt, - (PRConnectFN)_PR_InvalidStatus, - (PRAcceptFN)_PR_InvalidDesc, - (PRBindFN)_PR_InvalidStatus, - (PRListenFN)_PR_InvalidStatus, - (PRShutdownFN)_PR_InvalidStatus, - (PRRecvFN)_PR_InvalidInt, - (PRSendFN)_PR_InvalidInt, - (PRRecvfromFN)_PR_InvalidInt, - (PRSendtoFN)_PR_InvalidInt, + (PRWritevFN)_PR_InvalidInt, + (PRConnectFN)_PR_InvalidStatus, + (PRAcceptFN)_PR_InvalidDesc, + (PRBindFN)_PR_InvalidStatus, + (PRListenFN)_PR_InvalidStatus, + (PRShutdownFN)_PR_InvalidStatus, + (PRRecvFN)_PR_InvalidInt, + (PRSendFN)_PR_InvalidInt, + (PRRecvfromFN)_PR_InvalidInt, + (PRSendtoFN)_PR_InvalidInt, (PRPollFN)_PR_InvalidInt16, - (PRAcceptreadFN)_PR_InvalidInt, - (PRTransmitfileFN)_PR_InvalidInt, - (PRGetsocknameFN)_PR_InvalidStatus, - (PRGetpeernameFN)_PR_InvalidStatus, - (PRReservedFN)_PR_InvalidInt, - (PRReservedFN)_PR_InvalidInt, + (PRAcceptreadFN)_PR_InvalidInt, + (PRTransmitfileFN)_PR_InvalidInt, + (PRGetsocknameFN)_PR_InvalidStatus, + (PRGetpeernameFN)_PR_InvalidStatus, + (PRReservedFN)_PR_InvalidInt, + (PRReservedFN)_PR_InvalidInt, (PRGetsocketoptionFN)_PR_InvalidStatus, (PRSetsocketoptionFN)_PR_InvalidStatus, - (PRSendfileFN)_PR_InvalidInt, + (PRSendfileFN)_PR_InvalidInt, (PRConnectcontinueFN)_PR_InvalidStatus, (PRReservedFN)_PR_InvalidInt, (PRReservedFN)_PR_InvalidInt, @@ -106,159 +106,159 @@ PR_IMPLEMENT(PRStatus) PR_Close(PRFileDesc *fd) PR_IMPLEMENT(PRInt32) PR_Read(PRFileDesc *fd, void *buf, PRInt32 amount) { - return((fd->methods->read)(fd,buf,amount)); + return((fd->methods->read)(fd,buf,amount)); } PR_IMPLEMENT(PRInt32) PR_Write(PRFileDesc *fd, const void *buf, PRInt32 amount) { - return((fd->methods->write)(fd,buf,amount)); + return((fd->methods->write)(fd,buf,amount)); } PR_IMPLEMENT(PRInt32) PR_Seek(PRFileDesc *fd, PRInt32 offset, PRSeekWhence whence) { - return((fd->methods->seek)(fd, offset, whence)); + return((fd->methods->seek)(fd, offset, whence)); } PR_IMPLEMENT(PRInt64) PR_Seek64(PRFileDesc *fd, PRInt64 offset, PRSeekWhence whence) { - return((fd->methods->seek64)(fd, offset, whence)); + return((fd->methods->seek64)(fd, offset, whence)); } PR_IMPLEMENT(PRInt32) PR_Available(PRFileDesc *fd) { - return((fd->methods->available)(fd)); + return((fd->methods->available)(fd)); } PR_IMPLEMENT(PRInt64) PR_Available64(PRFileDesc *fd) { - return((fd->methods->available64)(fd)); + return((fd->methods->available64)(fd)); } PR_IMPLEMENT(PRStatus) PR_GetOpenFileInfo(PRFileDesc *fd, PRFileInfo *info) { - return((fd->methods->fileInfo)(fd, info)); + return((fd->methods->fileInfo)(fd, info)); } PR_IMPLEMENT(PRStatus) PR_GetOpenFileInfo64(PRFileDesc *fd, PRFileInfo64 *info) { - return((fd->methods->fileInfo64)(fd, info)); + return((fd->methods->fileInfo64)(fd, info)); } PR_IMPLEMENT(PRStatus) PR_Sync(PRFileDesc *fd) { - return((fd->methods->fsync)(fd)); + return((fd->methods->fsync)(fd)); } PR_IMPLEMENT(PRStatus) PR_Connect( PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout) { - return((fd->methods->connect)(fd,addr,timeout)); + return((fd->methods->connect)(fd,addr,timeout)); } PR_IMPLEMENT(PRStatus) PR_ConnectContinue( PRFileDesc *fd, PRInt16 out_flags) { - return((fd->methods->connectcontinue)(fd,out_flags)); + return((fd->methods->connectcontinue)(fd,out_flags)); } PR_IMPLEMENT(PRFileDesc*) PR_Accept(PRFileDesc *fd, PRNetAddr *addr, -PRIntervalTime timeout) + PRIntervalTime timeout) { - return((fd->methods->accept)(fd,addr,timeout)); + return((fd->methods->accept)(fd,addr,timeout)); } PR_IMPLEMENT(PRStatus) PR_Bind(PRFileDesc *fd, const PRNetAddr *addr) { - return((fd->methods->bind)(fd,addr)); + return((fd->methods->bind)(fd,addr)); } PR_IMPLEMENT(PRStatus) PR_Shutdown(PRFileDesc *fd, PRShutdownHow how) { - return((fd->methods->shutdown)(fd,how)); + return((fd->methods->shutdown)(fd,how)); } PR_IMPLEMENT(PRStatus) PR_Listen(PRFileDesc *fd, PRIntn backlog) { - return((fd->methods->listen)(fd,backlog)); + return((fd->methods->listen)(fd,backlog)); } PR_IMPLEMENT(PRInt32) PR_Recv(PRFileDesc *fd, void *buf, PRInt32 amount, -PRIntn flags, PRIntervalTime timeout) + PRIntn flags, PRIntervalTime timeout) { - return((fd->methods->recv)(fd,buf,amount,flags,timeout)); + return((fd->methods->recv)(fd,buf,amount,flags,timeout)); } PR_IMPLEMENT(PRInt32) PR_Send(PRFileDesc *fd, const void *buf, PRInt32 amount, -PRIntn flags, PRIntervalTime timeout) + PRIntn flags, PRIntervalTime timeout) { - return((fd->methods->send)(fd,buf,amount,flags,timeout)); + return((fd->methods->send)(fd,buf,amount,flags,timeout)); } PR_IMPLEMENT(PRInt32) PR_Writev(PRFileDesc *fd, const PRIOVec *iov, -PRInt32 iov_size, PRIntervalTime timeout) + PRInt32 iov_size, PRIntervalTime timeout) { if (iov_size > PR_MAX_IOVECTOR_SIZE) { PR_SetError(PR_BUFFER_OVERFLOW_ERROR, 0); return -1; } - return((fd->methods->writev)(fd,iov,iov_size,timeout)); + return((fd->methods->writev)(fd,iov,iov_size,timeout)); } PR_IMPLEMENT(PRInt32) PR_RecvFrom(PRFileDesc *fd, void *buf, PRInt32 amount, -PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout) + PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout) { - return((fd->methods->recvfrom)(fd,buf,amount,flags,addr,timeout)); + return((fd->methods->recvfrom)(fd,buf,amount,flags,addr,timeout)); } PR_IMPLEMENT(PRInt32) PR_SendTo( PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, const PRNetAddr *addr, PRIntervalTime timeout) { - return((fd->methods->sendto)(fd,buf,amount,flags,addr,timeout)); + return((fd->methods->sendto)(fd,buf,amount,flags,addr,timeout)); } PR_IMPLEMENT(PRInt32) PR_TransmitFile( PRFileDesc *sd, PRFileDesc *fd, const void *hdr, PRInt32 hlen, PRTransmitFileFlags flags, PRIntervalTime timeout) { - return((sd->methods->transmitfile)(sd,fd,hdr,hlen,flags,timeout)); + return((sd->methods->transmitfile)(sd,fd,hdr,hlen,flags,timeout)); } PR_IMPLEMENT(PRInt32) PR_AcceptRead( PRFileDesc *sd, PRFileDesc **nd, PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime timeout) { - return((sd->methods->acceptread)(sd, nd, raddr, buf, amount,timeout)); + return((sd->methods->acceptread)(sd, nd, raddr, buf, amount,timeout)); } PR_IMPLEMENT(PRStatus) PR_GetSockName(PRFileDesc *fd, PRNetAddr *addr) { - return((fd->methods->getsockname)(fd,addr)); + return((fd->methods->getsockname)(fd,addr)); } PR_IMPLEMENT(PRStatus) PR_GetPeerName(PRFileDesc *fd, PRNetAddr *addr) { - return((fd->methods->getpeername)(fd,addr)); + return((fd->methods->getpeername)(fd,addr)); } PR_IMPLEMENT(PRStatus) PR_GetSocketOption( PRFileDesc *fd, PRSocketOptionData *data) { - return((fd->methods->getsocketoption)(fd, data)); + return((fd->methods->getsocketoption)(fd, data)); } PR_IMPLEMENT(PRStatus) PR_SetSocketOption( PRFileDesc *fd, const PRSocketOptionData *data) { - return((fd->methods->setsocketoption)(fd, data)); + return((fd->methods->setsocketoption)(fd, data)); } PR_IMPLEMENT(PRInt32) PR_SendFile( - PRFileDesc *sd, PRSendFileData *sfd, - PRTransmitFileFlags flags, PRIntervalTime timeout) + PRFileDesc *sd, PRSendFileData *sfd, + PRTransmitFileFlags flags, PRIntervalTime timeout) { - return((sd->methods->sendfile)(sd,sfd,flags,timeout)); + return((sd->methods->sendfile)(sd,sfd,flags,timeout)); } PR_IMPLEMENT(PRInt32) PR_EmulateAcceptRead( @@ -274,7 +274,9 @@ PR_IMPLEMENT(PRInt32) PR_EmulateAcceptRead( ** operation - it waits indefinitely. */ accepted = PR_Accept(sd, &remote, PR_INTERVAL_NO_TIMEOUT); - if (NULL == accepted) return rv; + if (NULL == accepted) { + return rv; + } rv = PR_Recv(accepted, buf, amount, 0, timeout); if (rv >= 0) @@ -299,7 +301,7 @@ PR_IMPLEMENT(PRInt32) PR_EmulateAcceptRead( * they are sent before and after the file, respectively. * * PR_TRANSMITFILE_CLOSE_SOCKET flag - close socket after sending file - * + * * return number of bytes sent or -1 on error * */ @@ -310,7 +312,7 @@ PR_IMPLEMENT(PRInt32) PR_EmulateAcceptRead( * An implementation based on memory-mapped files */ -#define SENDFILE_MMAP_CHUNK (256 * 1024) +#define SENDFILE_MMAP_CHUNK (256 * 1024) PR_IMPLEMENT(PRInt32) PR_EmulateSendFile( PRFileDesc *sd, PRSendFileData *sfd, @@ -333,7 +335,7 @@ PR_IMPLEMENT(PRInt32) PR_EmulateSendFile( goto done; } if (sfd->file_nbytes && - (info.size < (sfd->file_offset + sfd->file_nbytes))) { + (info.size < (sfd->file_offset + sfd->file_nbytes))) { /* * there are fewer bytes in file to send than specified */ @@ -341,10 +343,12 @@ PR_IMPLEMENT(PRInt32) PR_EmulateSendFile( count = -1; goto done; } - if (sfd->file_nbytes) + if (sfd->file_nbytes) { file_bytes = sfd->file_nbytes; - else + } + else { file_bytes = info.size - sfd->file_offset; + } alignment = PR_GetMemMapAlignment(); @@ -400,8 +404,9 @@ PR_IMPLEMENT(PRInt32) PR_EmulateSendFile( index++; } rv = PR_Writev(sd, iov, index, timeout); - if (len) + if (len) { PR_MemUnmap(addr, mmap_len); + } if (rv < 0) { count = -1; goto done; @@ -411,8 +416,9 @@ PR_IMPLEMENT(PRInt32) PR_EmulateSendFile( file_bytes -= len; count += rv; - if (!file_bytes) /* header, file and trailer are sent */ + if (!file_bytes) { /* header, file and trailer are sent */ goto done; + } /* * send remaining bytes of the file, if any @@ -449,14 +455,17 @@ PR_IMPLEMENT(PRInt32) PR_EmulateSendFile( if (rv >= 0) { PR_ASSERT(rv == sfd->tlen); count += rv; - } else + } else { count = -1; + } } done: - if (mapHandle) + if (mapHandle) { PR_CloseFileMap(mapHandle); - if ((count >= 0) && (flags & PR_TRANSMITFILE_CLOSE_SOCKET)) + } + if ((count >= 0) && (flags & PR_TRANSMITFILE_CLOSE_SOCKET)) { PR_Close(sd); + } return count; } @@ -584,10 +593,12 @@ PR_IMPLEMENT(PRInt32) PR_EmulateSendFile( rv = count; done: - if (buf) + if (buf) { PR_DELETE(buf); - if ((rv >= 0) && (flags & PR_TRANSMITFILE_CLOSE_SOCKET)) + } + if ((rv >= 0) && (flags & PR_TRANSMITFILE_CLOSE_SOCKET)) { PR_Close(sd); + } return rv; } |