From e517bcea7c618241ad58ca981940e8d0ff55b899 Mon Sep 17 00:00:00 2001 From: Unbit Date: Wed, 27 Feb 2013 08:30:14 +0100 Subject: [PATCH] implemented Mono send file from handle --- plugins/mono/mono_plugin.c | 10 ++++++++++ plugins/mono/uwsgi.cs | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/mono/mono_plugin.c b/plugins/mono/mono_plugin.c index 1dc87d62..6316c387 100644 --- a/plugins/mono/mono_plugin.c +++ b/plugins/mono/mono_plugin.c @@ -146,6 +146,15 @@ static void uwsgi_mono_method_FlushResponse(MonoObject *this, int is_final) { uwsgi_response_write_body_do(wsgi_req, "", 0); } +static void uwsgi_mono_method_SendResponseFromFd(MonoObject *this, int fd, long offset, long len) { + struct wsgi_request *wsgi_req = current_wsgi_req(); + wsgi_req->sendfile_fd = fd; + if (fd >= 0) { + uwsgi_response_sendfile_do(wsgi_req, fd, offset, len); + } + wsgi_req->sendfile_fd = -1; +} + static void uwsgi_mono_method_SendResponseFromFile(MonoObject *this, MonoString *filename, long offset, long len) { struct wsgi_request *wsgi_req = current_wsgi_req(); int fd = open(mono_string_to_utf8(filename), O_RDONLY); @@ -206,6 +215,7 @@ static void uwsgi_mono_add_internal_calls() { mono_add_internal_call("uwsgi.uWSGIRequest::GetFilePath", uwsgi_mono_method_GetFilePath); mono_add_internal_call("uwsgi.uWSGIRequest::GetUriPath", uwsgi_mono_method_GetUriPath); mono_add_internal_call("uwsgi.uWSGIRequest::SendResponseFromFile", uwsgi_mono_method_SendResponseFromFile); + mono_add_internal_call("uwsgi.uWSGIRequest::SendResponseFromFd", uwsgi_mono_method_SendResponseFromFd); mono_add_internal_call("uwsgi.uWSGIRequest::GetHeaderByName", uwsgi_mono_method_GetHeaderByName); mono_add_internal_call("uwsgi.uWSGIRequest::ReadEntityBody", uwsgi_mono_method_ReadEntityBody); mono_add_internal_call("uwsgi.uWSGIRequest::GetTotalEntityBodyLength", uwsgi_mono_method_GetTotalEntityBodyLength); diff --git a/plugins/mono/uwsgi.cs b/plugins/mono/uwsgi.cs index 21a6e533..b20c7068 100644 --- a/plugins/mono/uwsgi.cs +++ b/plugins/mono/uwsgi.cs @@ -93,8 +93,11 @@ namespace uwsgi { [MethodImplAttribute(MethodImplOptions.InternalCall)] extern public override void SendResponseFromMemory(byte[] chunk, int length); + [MethodImplAttribute(MethodImplOptions.InternalCall)] + extern public void SendResponseFromFd(int fd, long offset, long length); + public override void SendResponseFromFile (IntPtr handle, long offset, long length) { - Console.WriteLine("sending a file"); + SendResponseFromFd(handle.ToInt32(), offset, length); } [MethodImplAttribute(MethodImplOptions.InternalCall)]