diff --git a/Parallel/IPCSocket.vb b/Parallel/IPCSocket.vb index 5355527..8cab67e 100644 --- a/Parallel/IPCSocket.vb +++ b/Parallel/IPCSocket.vb @@ -63,6 +63,7 @@ Public Class IPCSocket : Implements ITaskDriver Public Function GetTask(request As RequestStream, remoteAddress As System.Net.IPEndPoint) As BufferPipe + Call Console.WriteLine($"[{GetHashCode.ToHexString}] get parallel task entry.") Return New DataPipe(Encoding.UTF8.GetBytes(target.GetJson)) End Function @@ -75,6 +76,12 @@ Public Class IPCSocket : Implements ITaskDriver Return pipe End Function + + Public Function PostStart(request As RequestStream, remoteAddress As System.Net.IPEndPoint) As BufferPipe + Call Console.WriteLine($"[{GetHashCode.ToHexString}] started!") + Return New DataPipe(Encoding.UTF8.GetBytes("OK!")) + End Function + Public Function GetArgumentNumber(request As RequestStream, remoteAddress As System.Net.IPEndPoint) As BufferPipe Return New DataPipe(BitConverter.GetBytes(nargs)) diff --git a/Parallel/Protocols.vb b/Parallel/Protocols.vb index 5ce6078..2ae25f7 100644 --- a/Parallel/Protocols.vb +++ b/Parallel/Protocols.vb @@ -2,5 +2,6 @@ GetTask GetArgumentNumber GetArgumentByIndex + PostStart PostResult End Enum diff --git a/Parallel/SlaveTask.vb b/Parallel/SlaveTask.vb index ab6b3ce..4bfe1d7 100644 --- a/Parallel/SlaveTask.vb +++ b/Parallel/SlaveTask.vb @@ -31,7 +31,9 @@ Public Class SlaveTask Return Me End Function - Private Function handlePOST(buf As Stream, type As Type) As Object + Private Function handlePOST(buf As Stream, type As Type, debugCode As Integer) As Object + Call Console.WriteLine($"[{debugCode.ToHexString}] task finished!") + If fromBuffer.ContainsKey(type) Then Return fromBuffer(type)(buf) Else @@ -39,9 +41,11 @@ Public Class SlaveTask End If End Function - Private Function handleGET(param As Object) As ObjectStream + Private Function handleGET(param As Object, i As Integer, debugCode As Integer) As ObjectStream Dim type As Type = param.GetType + Call Console.WriteLine($"[{debugCode.ToHexString}] get argument[{i + 1}]...") + If toBuffers.ContainsKey(type) Then Return New ObjectStream(New TypeInfo(type, fullpath:=True), StreamMethods.Emit, toBuffers(type)(param)) Else @@ -55,12 +59,16 @@ Public Class SlaveTask Public Function RunTask(entry As [Delegate], ParamArray parameters As Object()) As Object Dim target As New IDelegate(entry) Dim result As Object = Nothing - Dim host As New IPCSocket(target, debugPort) With { - .handlePOSTResult = Sub(buf) result = handlePOST(buf, entry.Method.ReturnType), + Dim host As IPCSocket = Nothing + + host = New IPCSocket(target, debugPort) With { + .handlePOSTResult = Sub(buf) result = handlePOST(buf, entry.Method.ReturnType, host.GetHashCode), .nargs = parameters.Length, - .handleGetArgument = Function(i) handleGET(parameters(i)) + .handleGetArgument = Function(i) handleGET(parameters(i), i, host.GetHashCode) } + Call Console.WriteLine($"[{host.GetHashCode.ToHexString}] port:{host.HostPort}") + Call New Thread(AddressOf host.Run).Start() Call Thread.Sleep(100) diff --git a/Parallel/TaskBuilder.vb b/Parallel/TaskBuilder.vb index 4c5702d..f7bdda6 100644 --- a/Parallel/TaskBuilder.vb +++ b/Parallel/TaskBuilder.vb @@ -35,6 +35,8 @@ Public Class TaskBuilder : Implements ITaskDriver End If Next + ' send debug message + Call New TcpRequest(masterPort).SendMessage(New RequestStream(IPCSocket.Protocol, Protocols.PostStart)) Call PostFinished(api.Invoke(Nothing, args.ToArray)) Return 0