Plan 9 from Bell Labs’s /usr/web/sources/contrib/anothy/src/lib/djb-ape/unix/socket_sendfile.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <unistd.h>
#include "socket.h"

#ifdef __linux__

#ifdef __GLIBC__
#include <sys/sendfile.h>
#else
#include <linux/unistd.h>
_syscall4(int,sendfile,int,out,int,in,long *,offset,unsigned long,count)
#endif

int socket_sendfile(int out,int in,uint32 offset,uint32 bytes) {
  return sendfile(out,in,&offset,bytes);
}

#else

#ifdef _HPUX_SOURCE

/* http://www.devresource.hp.com/STK/man/10.30/sendfile_2.html */
#include <sys/socket.h>
int socket_sendfile(int out,int in,uint32 offset,uint32 bytes) {
  return sendfile(out,in,offset,bytes,0,0);
}

#else

#define BUFSIZE 16384

int socket_sendfile(int out,int in,uint32 offset,uint32 bytes) {
  char buf[BUFSIZE];
  int n,m;
  int sent=0;
  if (lseek(in,offset,SEEK_SET) == -1)
    return -1;
  if ((n=read(in,buf,(bytes<BUFSIZE)?bytes:BUFSIZE))<0)
    return (sent?sent:-1);
  if ((m=write(out,buf,n))<0)
    return -1;
  return n;
}

#endif

#endif

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].