Quantcast

Forums | MacLife

You are not logged in.

#1 2009-01-27 2:23 pm

Elahrairah
Member
From: In front of his macbook.
Registered: 2003-02-08
Posts: 559

The infamous sendfile.h problem...

Hey everyone,
learning internet programming right now, and I'm working with send files over sockets. But everywhere I look, it looks like I need sys/sendfile.h, which apparently is not supported on macs...


So, I need either a library repository where I can download and install libc6-dev (which contains the file, I believe),
or some other way to get sendfile.h up and running in my system.

Anybody ever run into this?


Good judgement comes from experience,
And experience comes from bad judgement.

Offline

 

#2 2009-01-27 2:43 pm

resedit
Chicken Little
Royal Wombat
From: /dev/null
Registered: 1999-11-01
Posts: 50393
Website

Re: The infamous sendfile.h problem...

I believe that is part of the php source as well - do you have all of the dev tools installed?


In her right hand Jenny held the Bible of her mother
Jenny had a pistol in the other
-- Steve Taylor

Offline

 

#3 2009-01-27 3:27 pm

resedit
Chicken Little
Royal Wombat
From: /dev/null
Registered: 1999-11-01
Posts: 50393
Website

Re: The infamous sendfile.h problem...

Sorry - I read that as sendmail.h, not sendfile.h
sendfile.h should be part of your C library headers. I'm sure the the Apple C library has it as part of their C library, and you probably want to use theirs. It should be installed with the dev tools.


In her right hand Jenny held the Bible of her mother
Jenny had a pistol in the other
-- Steve Taylor

Offline

 

#4 2009-01-27 3:32 pm

resedit
Chicken Little
Royal Wombat
From: /dev/null
Registered: 1999-11-01
Posts: 50393
Website

Re: The infamous sendfile.h problem...

Ouch - http://mail-archives.apache.org/mod_mbo … park.de%3E

Nevermind.

Get a real OS wink

Or you could install glibc on OS X - or find the OS X libc way to accomplish the same task.


In her right hand Jenny held the Bible of her mother
Jenny had a pistol in the other
-- Steve Taylor

Offline

 

#5 2009-01-27 5:51 pm

Elahrairah
Member
From: In front of his macbook.
Registered: 2003-02-08
Posts: 559

Re: The infamous sendfile.h problem...

resedit wrote:

Get a real OS wink

Or you could install glibc on OS X - or find the OS X libc way to accomplish the same task.

I hear yeh. If I had any room on my hard drive, I would.

Hey wait, I'm on tiger... I can't even dual boot, can I? Dangit.

Last edited by Elahrairah (2009-01-27 6:38 pm)


Good judgement comes from experience,
And experience comes from bad judgement.

Offline

 

#6 2009-01-27 6:55 pm

Miles
Now I fight for wisdom!
Administrator
From: Michigan
Registered: 2001-07-21
Posts: 4506
Website

Re: The infamous sendfile.h problem...

sendfile(2) in 10.5

You don't need sendfile to send a file over a socket, it just makes it more efficient (and possibly easier).  This code should work perfectly well (but is untested):

Code:

#include <stdio.h>
#include <err.h>
#include <sys/types.h>
#include <sys/socket.h>
#define BUFSIZE 1024

int sd; /* socket descriptor */
FILE *fh; /* file handle */

/* ... open socket, file here ... */

char buffer[BUFSIZE];
size_t bytes_read;

while ((bytes_read = fread(buffer, 1, BUFSIZE, fh) != 0) {
    ssize_t bytes_sent, rv;
    bytes_sent = 0;
    while (bytes_sent < bytes_read) {
        rv = send(sd, buffer + bytes_sent, bytes_read - bytes_sent, 0);
        if (rv < 0) err("socket send() failed");
        bytes_sent += rv;
    }
}

Offline

 

#7 2009-01-27 7:24 pm

Elahrairah
Member
From: In front of his macbook.
Registered: 2003-02-08
Posts: 559

Re: The infamous sendfile.h problem...

I'm in Tiger, but thanks... now manually writing sendfile...


Good judgement comes from experience,
And experience comes from bad judgement.

Offline

 

Board footer

Powered by PunBB 1.2.6
© Copyright 2002–2005 Rickard Andersson