annotate daemon/AcceptThread.cs @ 26:45ff08d59fda

update CGM
author riono <e165729@ie.u-ryukyu.ac.jp>
date Tue, 12 Jan 2021 21:23:23 +0900
parents 52cb63c37218
children 0cd2684e401b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
1 using System;
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
2 using System.Net;
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
3 using System.Net.Sockets;
25
52cb63c37218 update ChristieDaemon
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 22
diff changeset
4 using System.Threading.Tasks;
22
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
5 using Christie_net.codegear;
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
6
21
d488eb23a29f add ThreadTest
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 namespace Christie_net.daemon {
d488eb23a29f add ThreadTest
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 public class AcceptThread {
22
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
9 private Socket soc;
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
10 public int counter = 0;
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
11 public CodeGearManager cgm;
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
12
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
13 public AcceptThread(Socket soc, CodeGearManager cgm) {
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
14 this.soc = soc;
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
15 this.cgm = cgm;
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
16 }
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
17
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
18 public void Run() {
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
19 while (true) {
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
20 try {
26
45ff08d59fda update CGM
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
21 Socket socket = null;
45ff08d59fda update CGM
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
22 socket = soc.Accept();
25
52cb63c37218 update ChristieDaemon
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 22
diff changeset
23 socket.NoDelay = true;
22
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
24 Console.WriteLine("Accept " + socket.LocalEndPoint + ":" + ((IPEndPoint)socket.LocalEndPoint).Port);
25
52cb63c37218 update ChristieDaemon
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 22
diff changeset
25
52cb63c37218 update ChristieDaemon
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 22
diff changeset
26 Connection connection = new Connection(socket, cgm);
22
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
27 string key = "accept" + counter;
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
28
26
45ff08d59fda update CGM
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
29 IncomingTcpConnection incoming = new IncomingTcpConnection(connection);
45ff08d59fda update CGM
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
30 Task.Factory.StartNew(
45ff08d59fda update CGM
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
31 () => incoming.Run(),
45ff08d59fda update CGM
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
32 TaskCreationOptions.LongRunning);
25
52cb63c37218 update ChristieDaemon
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 22
diff changeset
33 //cgm.SetAccept(key, in);
52cb63c37218 update ChristieDaemon
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 22
diff changeset
34
26
45ff08d59fda update CGM
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
35 OutboundTcpConnection outbound = new OutboundTcpConnection(connection);
45ff08d59fda update CGM
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
36 Task.Factory.StartNew(
45ff08d59fda update CGM
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
37 () => outbound.Run(),
45ff08d59fda update CGM
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
38 TaskCreationOptions.LongRunning);
25
52cb63c37218 update ChristieDaemon
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 22
diff changeset
39 counter++;
22
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
40 } catch (Exception e) {
25
52cb63c37218 update ChristieDaemon
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 22
diff changeset
41 Console.WriteLine(e.StackTrace);
22
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
42 }
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
43 }
970c7f587126 update AcceptThread
riono <e165729@ie.u-ryukyu.ac.jp>
parents: 21
diff changeset
44 }
21
d488eb23a29f add ThreadTest
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 }
d488eb23a29f add ThreadTest
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 }