diff --git a/.vs/261433/v15/.suo b/.vs/261433/v15/.suo
new file mode 100644
index 0000000..576f6d5
Binary files /dev/null and b/.vs/261433/v15/.suo differ
diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json
new file mode 100644
index 0000000..f8b4888
--- /dev/null
+++ b/.vs/ProjectSettings.json
@@ -0,0 +1,3 @@
+{
+ "CurrentProjectSetting": null
+}
\ No newline at end of file
diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json
new file mode 100644
index 0000000..9c8a0df
--- /dev/null
+++ b/.vs/VSWorkspaceState.json
@@ -0,0 +1,10 @@
+{
+ "ExpandedNodes": [
+ "",
+ "\\Assignments",
+ "\\Assignments\\HW1",
+ "\\Assignments\\HW1\\DNWS"
+ ],
+ "SelectedNode": "\\Assignments\\HW1\\DNWS\\Program.cs",
+ "PreviewInSolutionExplorer": false
+}
\ No newline at end of file
diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite
new file mode 100644
index 0000000..3937a77
Binary files /dev/null and b/.vs/slnx.sqlite differ
diff --git a/261433 b/261433
new file mode 160000
index 0000000..e93b799
--- /dev/null
+++ b/261433
@@ -0,0 +1 @@
+Subproject commit e93b79912da31f87e8592f972cbea47e0197f778
diff --git a/Assignments/HW1/261433 b/Assignments/HW1/261433
new file mode 160000
index 0000000..ca18797
--- /dev/null
+++ b/Assignments/HW1/261433
@@ -0,0 +1 @@
+Subproject commit ca18797c09b83ae573ea9a38d04dc874f9b01444
diff --git a/Assignments/HW1/DNWS/.vs/DNWS/v15/.suo b/Assignments/HW1/DNWS/.vs/DNWS/v15/.suo
new file mode 100644
index 0000000..4f00dfb
Binary files /dev/null and b/Assignments/HW1/DNWS/.vs/DNWS/v15/.suo differ
diff --git a/Assignments/HW1/DNWS/.vs/DNWS/v15/Server/sqlite3/db.lock b/Assignments/HW1/DNWS/.vs/DNWS/v15/Server/sqlite3/db.lock
new file mode 100644
index 0000000..e69de29
diff --git a/Assignments/HW1/DNWS/.vs/DNWS/v15/Server/sqlite3/storage.ide b/Assignments/HW1/DNWS/.vs/DNWS/v15/Server/sqlite3/storage.ide
new file mode 100644
index 0000000..dc73a23
Binary files /dev/null and b/Assignments/HW1/DNWS/.vs/DNWS/v15/Server/sqlite3/storage.ide differ
diff --git a/Assignments/HW1/DNWS/.vs/DNWS/v15/Server/sqlite3/storage.ide-shm b/Assignments/HW1/DNWS/.vs/DNWS/v15/Server/sqlite3/storage.ide-shm
new file mode 100644
index 0000000..f07af47
Binary files /dev/null and b/Assignments/HW1/DNWS/.vs/DNWS/v15/Server/sqlite3/storage.ide-shm differ
diff --git a/Assignments/HW1/DNWS/.vs/DNWS/v15/Server/sqlite3/storage.ide-wal b/Assignments/HW1/DNWS/.vs/DNWS/v15/Server/sqlite3/storage.ide-wal
new file mode 100644
index 0000000..2b8a636
Binary files /dev/null and b/Assignments/HW1/DNWS/.vs/DNWS/v15/Server/sqlite3/storage.ide-wal differ
diff --git a/Assignments/HW1/DNWS/Clientinfo.cs b/Assignments/HW1/DNWS/Clientinfo.cs
new file mode 100644
index 0000000..a44980e
--- /dev/null
+++ b/Assignments/HW1/DNWS/Clientinfo.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Net.Sockets;
+using System.Threading;
+using System.Net;
+using System.IO;
+using System.Diagnostics;
+
+namespace DNWS
+{
+ class ClientInfo : IPlugin
+ {
+ public ClientInfo()
+ {
+
+ }
+
+ public void PreProcessing(HTTPRequest request)
+ {
+ throw new NotImplementedException();
+ }
+
+ public HTTPResponse GetResponse(HTTPRequest request)//ref. 600611030
+ {
+ HTTPResponse response = null;
+ StringBuilder sb = new StringBuilder();
+ string[] remoteEndpoint = request.getPropertyByKey("RemoteEndPoint").Split(':');
+ string ip = remoteEndpoint[0], port = remoteEndpoint[1];
+ sb.Append("
Client IP: " + ip + "");
+ sb.Append("Client Port: " + port + "");
+ sb.Append("Browser Information: " + request.getPropertyByKey("User-Agent") + "");
+ sb.Append("Accept-Language: " + request.getPropertyByKey("Accept-Language") + "");
+ sb.Append("Accept-Encoding: " + request.getPropertyByKey("Accept-Encoding") + "");
+ sb.Append("Thread ID: " + Thread.CurrentThread.ManagedThreadId + "");
+ //from https://stackoverflow.com/questions/15381174/how-to-count-the-amount-of-concurrent-threads-in-net-application
+ sb.Append("Amount of thread: " + Process.GetCurrentProcess().Threads.Count + "");
+ ThreadPool.GetAvailableThreads(out int workers, out int completion);
+ ThreadPool.GetMaxThreads(out int max_workers, out int max_completion);
+ sb.Append("Size of thread pool: " + max_workers + "
");
+ sb.Append("Available threads in thread pool: " + workers + "
");
+ sb.Append("Active threads in thread pool: " + (max_workers - workers) + "
");
+ sb.Append("");
+ response = new HTTPResponse(200);
+ response.body = Encoding.UTF8.GetBytes(sb.ToString());
+ return response;
+ }
+
+ public HTTPResponse PostProcessing(HTTPResponse response)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assignments/HW1/DNWS/DNWS.sln b/Assignments/HW1/DNWS/DNWS.sln
new file mode 100644
index 0000000..ae7ea10
--- /dev/null
+++ b/Assignments/HW1/DNWS/DNWS.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.27428.2005
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DNWS", "DNWS.csproj", "{EE9DB1C1-4B6D-4646-85E9-CADAB441EB52}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {EE9DB1C1-4B6D-4646-85E9-CADAB441EB52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {EE9DB1C1-4B6D-4646-85E9-CADAB441EB52}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EE9DB1C1-4B6D-4646-85E9-CADAB441EB52}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {EE9DB1C1-4B6D-4646-85E9-CADAB441EB52}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {EF126B8E-0932-4255-8960-735157571F53}
+ EndGlobalSection
+EndGlobal
diff --git a/Assignments/HW1/DNWS/Program.cs b/Assignments/HW1/DNWS/Program.cs
index 89a259a..f529ab0 100644
--- a/Assignments/HW1/DNWS/Program.cs
+++ b/Assignments/HW1/DNWS/Program.cs
@@ -150,7 +150,7 @@ protected HTTPResponse getFile(String path)
///
/// Get a request from client, process it, then return response to client
///
- public void Process()
+ public void Process(object state)
{
NetworkStream ns = new NetworkStream(_client);
string requestStr = "";
@@ -288,7 +288,8 @@ public void Start()
_parent.Log("Client accepted:" + clientSocket.RemoteEndPoint.ToString());
HTTPProcessor hp = new HTTPProcessor(clientSocket, _parent);
// Single thread
- hp.Process();
+ ThreadPool.SetMaxThreads(50, 50);
+ ThreadPool.QueueUserWorkItem(hp.Process);
// End single therad
}
diff --git a/Assignments/HW1/DNWS/StatPlugin.cs b/Assignments/HW1/DNWS/StatPlugin.cs
index aec7606..9e90bc8 100644
--- a/Assignments/HW1/DNWS/StatPlugin.cs
+++ b/Assignments/HW1/DNWS/StatPlugin.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
+using System.Threading;
+using System.Diagnostics;
namespace DNWS
{
@@ -30,9 +32,14 @@ public void PreProcessing(HTTPRequest request)
public HTTPResponse GetResponse(HTTPRequest request)
{
HTTPResponse response = null;
- StringBuilder sb = new StringBuilder();
- sb.Append("Stat:
");
- foreach (KeyValuePair entry in statDictionary)
+ ThreadPool.GetAvailableThreads(out int workers, out int completion);
+ ThreadPool.GetMaxThreads(out int max_workers, out int max_completion);
+ StringBuilder sb = new StringBuilder();
+ sb.Append("Stat:
");
+ sb.Append("Size of Threads: " + max_workers + "
");
+ sb.Append("Available Threads: " + workers + "
");
+ sb.Append("Active threads: " + (max_workers - workers) + "
");
+ foreach (KeyValuePair entry in statDictionary)
{
sb.Append(entry.Key + ": " + entry.Value.ToString() + "
");
}
diff --git a/Assignments/HW1/DNWS/config.json b/Assignments/HW1/DNWS/config.json
index 168ce81..d8eb07c 100644
--- a/Assignments/HW1/DNWS/config.json
+++ b/Assignments/HW1/DNWS/config.json
@@ -1,19 +1,25 @@
{
"DocumentRoot": ".",
"Port": "8080",
- "Plugins" : [
- {
- "Path" : "stat",
- "Class" : "DNWS.StatPlugin",
- "Preprocessing" : "true",
- "Postprocessing" : "false" ,
- "Singpleton" : "false"
- },
- {
- "Path" : "ox",
- "Class" : "DNWS.OXPlugin",
- "Preprocessing" : "false",
- "Postprocessing" :"false"
- }
- ]
+ "Plugins": [
+ {
+ "Path": "stat",
+ "Class": "DNWS.StatPlugin",
+ "Preprocessing": "true",
+ "Postprocessing": "false",
+ "Singpleton": "false"
+ },
+ {
+ "Path": "ox",
+ "Class": "DNWS.OXPlugin",
+ "Preprocessing": "false",
+ "Postprocessing": "false"
+ },
+ {
+ "Path": "clientinfo",
+ "Class": "DNWS.Clientinfo",
+ "Preprocessing": "false",
+ "Postprocessing": "false"
+ }
+ ]
}
\ No newline at end of file