Comments (23)
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.
Joseph, any news on this issue?
from bjoern.
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.
Let me know when you've got something working; I can help cleaning up then.
from bjoern.
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.
I guess none of the flags need to be set.
from bjoern.
I'm confused.
I mean the last argument in sendfile function,
Why?
from bjoern.
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.
I think we can reuse these code if you don't mind the server get bigger
from bjoern.
Flags: None should be set --> 0
value (as seen in the lighttpd example)
from bjoern.
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.
@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.
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.
Could you show your do_sendfile
code?
from bjoern.
#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.
Maybe FreeBSD's sendfile
doesn't move the file cursor? What data is sent over the socket connection? (Use wireshark, for instance)
from bjoern.
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.
What tool are you using for making HTTP requests?
from bjoern.
curl and chrome
from bjoern.
$ 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.
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.
oups seems like I introduced a bug in e88527b
from bjoern.
nope I didn't.
from bjoern.
Related Issues (20)
- unix sockets aren't released on SIGHUP HOT 3
- Bjoern 200-300 rps vs gunicorn 500/600 rps HOT 1
- site don't work
- pip install fails - missing http_parser.h HOT 2
- How to trigger server restart on source file changes? HOT 1
- Build fails on M1 Mac using Homebrew HOT 9
- calling from command line like gunicorn in Profcfile HOT 2
- Build bjoern error in mac m1 with command `pip3 install --global-option=build_ext --global-option="-I/opt/homebrew/include" bjoern` HOT 6
- Production use HOT 1
- Remove flask example HOT 5
- pip install not working on ubuntu 20.04 HOT 5
- Compilation terminated - fatal error: http_parser.h: No such file or directory HOT 1
- Extending to asgi HOT 7
- pip install error HOT 1
- Autostart after changes HOT 1
- broken pipe after running for a while HOT 3
- symbol not found in flat namespace '_ev_cleanup_start'
- pip installation fails (bjoern/request.h:4:10: fatal error: 'ev.h' file not found) HOT 2
- Apple Silicon build not supported. HOT 7
- ev.h not found; command /usr/bin/gcc exit failed with exit code 1 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bjoern.