File: uwsgi.cs

package info (click to toggle)
uwsgi 2.0.31-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,564 kB
  • sloc: ansic: 87,066; python: 7,004; cpp: 1,133; java: 708; perl: 678; sh: 585; ruby: 555; makefile: 148; xml: 130; cs: 121; objc: 37; php: 28; erlang: 20; javascript: 11
file content (170 lines) | stat: -rw-r--r-- 5,011 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
using System;
using System.IO;
using System.Net;
using System.Web;
using System.Web.Hosting;
using System.Text;
using System.Runtime.CompilerServices;

[assembly: System.Reflection.AssemblyVersion ("0.0.0.1")]

namespace uwsgi {

	public delegate void uWSGIHook();
	public delegate void uWSGIHook1(int signum);

	public class api {
		static uWSGIHook postfork_hook = null;

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public static void RegisterSignal(int signum, string target, uWSGIHook1 func);

		public static void PostFork(uWSGIHook func) {
			postfork_hook = func;
		}

		public static void RunPostForkHook() {
			if (postfork_hook != null) {
				postfork_hook();
			}
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public static int WorkerId();

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public static void Signal(int signum);

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
                extern public static byte[] CacheGet(string key, string cache=null);
	}

	class uWSGIRequest: HttpWorkerRequest {

		private String filepath = null;

		public override string GetAppPath() {
			return "/";
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public override string GetServerVariable(string name);

		public override bool IsEntireEntityBodyIsPreloaded() {
			return false;
		}

		public override string GetUnknownRequestHeader(string name) {
			return GetHeaderByName(name);
		}

		public override byte[] GetPreloadedEntityBody() {
			return null;
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public string GetHeaderByName(string name);
	

		public override string GetKnownRequestHeader(int index) {
			return GetHeaderByName(GetKnownRequestHeaderName(index));
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public override int GetTotalEntityBodyLength();

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public override int ReadEntityBody(byte[] buffer, int size);

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public override string GetFilePath();

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public override string MapPath(string virtualPath);

		public override void EndOfRequest() {
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public override void FlushResponse(bool finalFlush);

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public override string GetHttpVerbName();

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public override string GetHttpVersion();

		public override string GetLocalAddress() {
			return GetServerVariable("SERVER_ADDR");
		}

		public override int GetLocalPort() {
			return Convert.ToInt32(GetServerVariable("SERVER_PORT"));
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public override string GetQueryString();

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public override string GetRawUrl();

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public override string GetRemoteAddress();

		public override int GetRemotePort() {
			return Convert.ToInt32(GetServerVariable("REMOTE_PORT"));
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public override string GetUriPath();

		public override void SendKnownResponseHeader (int index, string value) {
			string headerName = HttpWorkerRequest.GetKnownResponseHeaderName (index);
                	SendUnknownResponseHeader (headerName, value);
		}

		[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) {
			SendResponseFromFd(handle.ToInt32(), offset, length);
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public override void SendResponseFromFile(string filename, long offset, long length);
	
		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public override void SendStatus(int status, string msg);

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		extern public override void SendUnknownResponseHeader (string name, string value);

		public string hack_current_filename() {
			return filepath;
		}
	}

	public class uWSGIApplicationHost: MarshalByRefObject {
		public void ProcessRequest() {
			uWSGIRequest ur = new uWSGIRequest();
			HttpRuntime.ProcessRequest(ur);
		}
	}

	public class uWSGIApplication {

		public uWSGIApplicationHost appHost;

		public uWSGIApplication(string virtualPath, string physicalPath) {
			appHost = (uWSGIApplicationHost)ApplicationHost.CreateApplicationHost(typeof(uWSGIApplicationHost), virtualPath, physicalPath);
		}

		public void Request() {
			appHost.ProcessRequest();
		}
	}

}