Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mongoose
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Gitlab has been updated. More info
here
and
there
.
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
94dccdd6
Commit
94dccdd6
authored
10 years ago
by
Sergey Lyubka
Browse files
Options
Downloads
Patches
Plain Diff
c# -> csharp
parent
544352b7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/c#/example.cs
+0
-43
0 additions, 43 deletions
examples/c#/example.cs
examples/c#/mongoose.cs
+0
-68
0 additions, 68 deletions
examples/c#/mongoose.cs
with
0 additions
and
111 deletions
examples/c#/example.cs
deleted
100644 → 0
+
0
−
43
View file @
544352b7
// This file is part of mongoose web server project,
// https://github.com/cesanta/mongoose
using
System
;
public
class
Program
{
static
private
int
EventHandler
(
IntPtr
conn_ptr
,
int
ev
)
{
MongooseConnection
conn
=
(
MongooseConnection
)
System
.
Runtime
.
InteropServices
.
Marshal
.
PtrToStructure
(
conn_ptr
,
typeof
(
MongooseConnection
));
if
(
ev
==
102
)
{
// MG_AUTH
return
1
;
}
else
if
(
ev
==
103
)
{
// MG_REQUEST
Mongoose
.
send_data
(
conn_ptr
,
"Hello from C#!\n"
);
Mongoose
.
send_data
(
conn_ptr
,
"URI: "
+
conn
.
uri
+
"\n"
);
Mongoose
.
send_data
(
conn_ptr
,
"HTTP Headers:\n"
);
for
(
int
i
=
0
;
i
<
conn
.
num_headers
;
i
++)
{
IntPtr
name
=
conn
.
http_headers
[
i
].
name
;
IntPtr
val
=
conn
.
http_headers
[
i
].
value
;
System
.
Runtime
.
InteropServices
.
Marshal
.
PtrToStringAnsi
(
name
);
Mongoose
.
send_data
(
conn_ptr
,
" "
+
System
.
Runtime
.
InteropServices
.
Marshal
.
PtrToStringAnsi
(
name
)
+
": "
+
System
.
Runtime
.
InteropServices
.
Marshal
.
PtrToStringAnsi
(
val
)
+
"\n"
);
}
return
1
;
}
return
0
;
}
static
void
Main
()
{
Mongoose
web_server
=
new
Mongoose
(
"."
,
"9001"
,
new
MongooseEventHandler
(
EventHandler
));
Console
.
WriteLine
(
"Mongoose started, press Ctrl-C to exit."
);
for
(;;)
{
web_server
.
poll
(
1000
);
}
}
}
This diff is collapsed.
Click to expand it.
examples/c#/mongoose.cs
deleted
100644 → 0
+
0
−
68
View file @
544352b7
// This file is part of mongoose web server project,
// https://github.com/cesanta/mongoose
using
System
;
using
System.Runtime.InteropServices
;
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
MongooseHeader
{
[
MarshalAs
(
UnmanagedType
.
LPTStr
)]
public
IntPtr
name
;
[
MarshalAs
(
UnmanagedType
.
LPTStr
)]
public
IntPtr
value
;
};
// mongoose.h :: struct mg_connection
[
StructLayout
(
LayoutKind
.
Sequential
)]
public
struct
MongooseConnection
{
[
MarshalAs
(
UnmanagedType
.
LPTStr
)]
public
string
request_method
;
[
MarshalAs
(
UnmanagedType
.
LPTStr
)]
public
string
uri
;
[
MarshalAs
(
UnmanagedType
.
LPTStr
)]
public
string
http_version
;
[
MarshalAs
(
UnmanagedType
.
LPTStr
)]
public
string
query_string
;
[
MarshalAs
(
UnmanagedType
.
ByValArray
,
SizeConst
=
48
)]
public
char
[]
remote_ip
;
[
MarshalAs
(
UnmanagedType
.
LPTStr
)]
public
string
local_ip
;
[
MarshalAs
(
UnmanagedType
.
U2
)]
public
short
remote_port
;
[
MarshalAs
(
UnmanagedType
.
U2
)]
public
short
local_port
;
[
MarshalAs
(
UnmanagedType
.
SysInt
)]
public
int
num_headers
;
[
MarshalAs
(
UnmanagedType
.
ByValArray
,
SizeConst
=
30
)]
public
MongooseHeader
[]
http_headers
;
[
MarshalAs
(
UnmanagedType
.
LPTStr
)]
public
IntPtr
content
;
[
MarshalAs
(
UnmanagedType
.
SysInt
)]
public
int
content_len
;
[
MarshalAs
(
UnmanagedType
.
SysInt
)]
public
int
is_websocket
;
[
MarshalAs
(
UnmanagedType
.
SysInt
)]
public
int
status_code
;
[
MarshalAs
(
UnmanagedType
.
SysInt
)]
public
int
wsbits
;
};
public
delegate
int
MongooseEventHandler
(
IntPtr
c
,
int
ev
);
public
class
Mongoose
{
public
const
string
dll_
=
"mongoose"
;
private
IntPtr
server_
;
[
DllImport
(
dll_
)]
private
static
extern
IntPtr
mg_create_server
(
IntPtr
user_data
,
MongooseEventHandler
eh
);
[
DllImport
(
dll_
)]
private
static
extern
int
mg_poll_server
(
IntPtr
server
,
int
milli
);
[
DllImport
(
dll_
)]
private
static
extern
IntPtr
mg_set_option
(
IntPtr
server
,
string
name
,
string
value
);
[
DllImport
(
dll_
)]
public
static
extern
int
mg_send_data
(
IntPtr
conn
,
string
data
,
int
length
);
public
Mongoose
(
string
document_root
,
string
listening_port
,
MongooseEventHandler
event_handler
)
{
server_
=
mg_create_server
(
IntPtr
.
Zero
,
event_handler
);
mg_set_option
(
server_
,
"document_root"
,
document_root
);
mg_set_option
(
server_
,
"listening_port"
,
listening_port
);
}
public
static
int
send_data
(
IntPtr
conn
,
string
data
)
{
return
mg_send_data
(
conn
,
data
,
data
.
Length
);
}
public
void
poll
(
int
milli
)
{
mg_poll_server
(
server_
,
milli
);
}
// TODO: add destructor and call mg_destroy_server()
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment