/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "primpl.h"
#include <string.h>
/*****************************************************************************/
/************************** Invalid I/O method object ************************/
/*****************************************************************************/
(PRDescType)0,
};
{
PR_ASSERT(!"I/O method is invalid");
return -1;
} /* _PR_InvalidInt */
{
PR_ASSERT(!"I/O method is invalid");
return -1;
} /* _PR_InvalidInt */
{
PR_ASSERT(!"I/O method is invalid");
return rv;
} /* _PR_InvalidInt */
/*
* An invalid method that returns PRStatus
*/
{
PR_ASSERT(!"I/O method is invalid");
return PR_FAILURE;
} /* _PR_InvalidDesc */
/*
* An invalid method that returns a pointer
*/
{
PR_ASSERT(!"I/O method is invalid");
return NULL;
} /* _PR_InvalidDesc */
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
if (iov_size > PR_MAX_IOVECTOR_SIZE)
{
return -1;
}
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
/*
** The timeout does not apply to the accept portion of the
** operation - it waits indefinitely.
*/
if (rv >= 0)
{
/* copy the new info out where caller can see it */
return rv;
}
return rv;
}
/*
* PR_EmulateSendFile
*
* 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
*
*/
/*
* An implementation based on memory-mapped files
*/
{
/* Get file size */
count = -1;
goto done;
}
if (sfd->file_nbytes &&
/*
* there are fewer bytes in file to send than specified
*/
count = -1;
goto done;
}
if (sfd->file_nbytes)
else
/* number of initial bytes to skip in mmap'd segment */
/* find previous mmap alignment boundary */
/*
* If the file is large, mmap and send the file in chunks so as
* to not consume too much virtual address space
*/
/*
* Map in (part of) file. Take care of zero-length files.
*/
if (len) {
if (!mapHandle) {
count = -1;
goto done;
}
if (!addr) {
count = -1;
goto done;
}
}
/*
* send headers first, followed by the file
*/
index++;
}
if (len) {
index++;
}
/*
* all file data is mapped in; send the trailer too
*/
index++;
}
if (len)
if (rv < 0) {
count = -1;
goto done;
}
file_bytes -= len;
if (!file_bytes) /* header, file and trailer are sent */
goto done;
/*
* send remaining bytes of the file, if any
*/
while (len > 0) {
/*
* Map in (part of) file
*/
if (!addr) {
count = -1;
goto done;
}
if (rv < 0) {
count = -1;
goto done;
}
file_bytes -= rv;
}
PR_ASSERT(0 == file_bytes);
if (rv >= 0) {
} else
count = -1;
}
done:
if (mapHandle)
return count;
}
#else
{
const void * buffer;
char *buf;
return -1;
}
/*
* send header first
*/
while (buflen) {
if (rv < 0) {
/* PR_Send() has invoked PR_SetError(). */
rv = -1;
goto done;
} else {
}
}
/*
* send file next
*/
rv = -1;
goto done;
}
if (sendbytes == 0) {
/* send entire file */
while (rlen) {
if (rv < 0) {
/* PR_Send() has invoked PR_SetError(). */
rv = -1;
goto done;
} else {
}
}
}
if (rlen < 0) {
/* PR_Read() has invoked PR_SetError(). */
rv = -1;
goto done;
}
} else {
while (rlen) {
if (rv < 0) {
/* PR_Send() has invoked PR_SetError(). */
rv = -1;
goto done;
} else {
}
}
}
if (rlen < 0) {
/* PR_Read() has invoked PR_SetError(). */
rv = -1;
goto done;
} else if (sendbytes != 0) {
/*
* there are fewer bytes in file to send than specified
*/
rv = -1;
goto done;
}
}
/*
* send trailer last
*/
while (buflen) {
if (rv < 0) {
/* PR_Send() has invoked PR_SetError(). */
rv = -1;
goto done;
} else {
}
}
done:
if (buf)
return rv;
}
#endif
/* priometh.c */