Git Product home page Git Product logo

Comments (23)

jonashaag avatar jonashaag commented on September 25, 2024

Well I don't have a BSD system but I'll gladly accept patches if they're not too ugly... so go ahead, do the port, and open a pull request :)

Thanks!

from bjoern.

jonashaag avatar jonashaag commented on September 25, 2024

Joseph, any news on this issue?

from bjoern.

 avatar commented on September 25, 2024

I found some ugly ways, but I think it's too ugly to make a pull.
I read lots of code from nginx trying to find a nice way, but ...
A module called "py-sendfile" give a wrapped sendfile function,this module give me some inspiration,now I'm working on it.
Here is link for py-sendfile ->" http://pypi.python.org/pypi/py-sendfile " ,
just like the apple hit Newton and me, I think you can find a nice way to solve this. :)
By the way, I'm just a fresh man in such project and university life, lots of thing need me to learn.
I have learned a lot from this project, Thank you and your nice job!

from bjoern.

jonashaag avatar jonashaag commented on September 25, 2024

Let me know when you've got something working; I can help cleaning up then.

from bjoern.

 avatar commented on September 25, 2024

This is the sendfile defined in FreeBSD
int sendfile(int fd, int s, off_t offset, size_t nbytes, struct sf_hdtr *hdtr, off_t *sbytes, int flags);
Here is the define in Linux
ssize_t sendfile(int out_fd, int in_fd, off_t * offset ", size_t" " count" );
One problem is the Flags argument , I don't know choice which one, ie which one is more proper,
SF_NODISKIO , SF_MNOWAIT or SF_SYNC
Here is the man page->" http://www.freebsd.org/cgi/man.cgi?query=sendfile&sektion=2"
The way I choice is to wrappe the sendfile function to make it just like it Linux , I'm not sure whether it will work fine.

from bjoern.

jonashaag avatar jonashaag commented on September 25, 2024

I guess none of the flags need to be set.

from bjoern.

 avatar commented on September 25, 2024

I'm confused.
I mean the last argument in sendfile function,
Why?

from bjoern.

 avatar commented on September 25, 2024

These are the code sample from lighttpd's network_sendfile, This maybe useful.
/* FreeBSD sendfile() _/
/_From file network_freebsd_sendfile.c */
if (-1 == sendfile(c->file.fd, fd, offset, toSend, NULL, &r, 0))

/* Linux sendfile() _/
/_From file network_linux_sendfile.c */
if (-1 == (r = sendfile(fd, c->file.fd, &offset, toSend)))

from bjoern.

 avatar commented on September 25, 2024

I think we can reuse these code if you don't mind the server get bigger

from bjoern.

jonashaag avatar jonashaag commented on September 25, 2024

Flags: None should be set --> 0 value (as seen in the lighttpd example)

from bjoern.

ottob avatar ottob commented on September 25, 2024

Thanks for looking at this. OpenBSD currently doesn't have sendfile at all. It would be great if sendfile could be made optional.

from bjoern.

jonashaag avatar jonashaag commented on September 25, 2024

@ottob: That should be quite easy to implement... an #ifdef around request.c L288-292 to not include wsgi.file_wrapper on OpenBSD. Feel free to send a pull request if it works.

from bjoern.

 avatar commented on September 25, 2024

After I replace the sendfile function with freebsd's , I still can't make it run properly.
It just run but never response.
Then I just left the do_sendfile always return true, but it still don't work.
Now I'm try to find why.
God bless!

from bjoern.

jonashaag avatar jonashaag commented on September 25, 2024

Could you show your do_sendfile code?

from bjoern.

 avatar commented on September 25, 2024
#if defined(__FreeBSD__) 
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>

static bool
do_sendfile(Request* request){
    Py_ssize_t bytes_sent ;
    int r = sendfile(
        request->current_chunk_p,
        request->client_fd, 
        NULL,
        SENDFILE_CHUNK_SIZE, 
        NULL, 
        &bytes_sent, 
        0);
    if(r == -1)
        return handle_nonzero_errno(request);
    return  bytes_sent !=0;
}

#elif defined(__Linux__)
#include <sys/sendfile.h>

static bool
do_sendfile(Request* request){
    Py_ssize_t bytes_sent = sendfile(
        request->client_fd,
        request->current_chunk_p,    // current_chunk_p stores the file fd 
        NULL, 
        SENDFILE_CHUNK_SIZE);
    if(bytes_sent == -1)
        return handle_nonzero_errno(request);
    return bytes_sent != 0;
}

#endif

from bjoern.

jonashaag avatar jonashaag commented on September 25, 2024

Maybe FreeBSD's sendfile doesn't move the file cursor? What data is sent over the socket connection? (Use wireshark, for instance)

from bjoern.

 avatar commented on September 25, 2024

I add a printf line to the do_sendfile and it never print something.
And I find when the server run to ev_io_read , after it return it just paused here,
and the request->state.parse_finished flag set to 0, so the server still waiting for more data.
So I guess it's not the do_sendfile's problem.There are other problem on FreeBSD.

from bjoern.

jonashaag avatar jonashaag commented on September 25, 2024

What tool are you using for making HTTP requests?

from bjoern.

 avatar commented on September 25, 2024

curl and chrome

from bjoern.

 avatar commented on September 25, 2024

$ curl -v http://192.168.226.130:8000/

  • About to connect() to 192.168.226.130 port 8000 (#0)
  • Trying 192.168.226.130... connected
  • Connected to 192.168.226.130 (192.168.226.130) port 8000 (#0)

    GET / HTTP/1.1
    User-Agent: curl/7.20.1 (i686-pc-cygwin) libcurl/7.20.1 OpenSSL/0.9.8r zlib/1.
    2.5 libidn/1.18 libssh2/1.2.5
    Host: 192.168.226.130:8000
    Accept: /

It just paused here

from bjoern.

 avatar commented on September 25, 2024

Ok, It works now!
I download the source from pypi(http://pypi.python.org/pypi/bjoern/1.2) not the git version.
And replace the sendfile function.
Now, I'm trying to find why and test the sendfile.
Thank all of you!

For fresh man like me, trying to install on FreeBSD, this maybe useful:
first install libev using" pkg_add -r libev "
second download the source from pypi
replace the do_sendfile as you like
then configure the gcc in your shell:
-> export CFLAGS="-I/usr/local/include"
-> export LDFLAGS="-L/usr/local/lib"
(by default pkg_add will install the libev in these paths but the gcc don't search them)
last, using the setup.py -> python setup.py install
(done!)

from bjoern.

jonashaag avatar jonashaag commented on September 25, 2024

oups seems like I introduced a bug in e88527b

from bjoern.

jonashaag avatar jonashaag commented on September 25, 2024

nope I didn't.

from bjoern.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.