| 1 |
#Region "Microsoft.VisualBasic::b0f12490536f283a929877085408362f, Microsoft.VisualBasic.Core\ApplicationServices\Parallel\MMFProtocol\Pipeline\Pipeline.vb"
|
| 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 |
#End Region
|
| 43 |
|
| 44 |
Imports Microsoft.VisualBasic.Net.Http
|
| 45 |
Imports Microsoft.VisualBasic.Net.Protocols
|
| 46 |
Imports Microsoft.VisualBasic.Net.Protocols.Reflection
|
| 47 |
Imports Microsoft.VisualBasic.Net.Tcp
|
| 48 |
|
| 49 |
Namespace Parallel.MMFProtocol.Pipeline
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
<Protocol(GetType(API.Protocols))>
|
| 56 |
Public Class Pipeline
|
| 57 |
|
| 58 |
ReadOnly _sockets As SortedDictionary(Of String, MapStream.MSWriter) =
|
| 59 |
New SortedDictionary(Of String, MapStream.MSWriter)
|
| 60 |
ReadOnly _netSocket As TcpServicesSocket
|
| 61 |
ReadOnly _protocols As Net.Abstract.IProtocolHandler
|
| 62 |
|
| 63 |
Sub New(Optional port As Integer = API.PeplinePort)
|
| 64 |
_protocols = New ProtocolHandler(Me)
|
| 65 |
_netSocket = New TcpServicesSocket(port)
|
| 66 |
_netSocket.Responsehandler = AddressOf _protocols.HandleRequest
|
| 67 |
|
| 68 |
Call Parallel.RunTask(AddressOf _netSocket.Run)
|
| 69 |
End Sub
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
Public Function GetValue(Of T As RawStream)(var As String) As T
|
| 78 |
If Not _sockets.ContainsKey(var) Then
|
| 79 |
Return Nothing
|
| 80 |
End If
|
| 81 |
|
| 82 |
Dim data As MapStream.MSWriter = _sockets(var)
|
| 83 |
Dim buf As Byte() = data.Read.byteData
|
| 84 |
Dim raw As Object = Activator.CreateInstance(GetType(T), {buf})
|
| 85 |
Dim x As T = DirectCast(raw, T)
|
| 86 |
Return x
|
| 87 |
End Function
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
<Protocol(API.Protocols.Allocation)>
|
| 94 |
Private Function __allocated(CA As Long, request As RequestStream, remote As System.Net.IPEndPoint) As RequestStream
|
| 95 |
Dim s As String = request.GetUTF8String
|
| 96 |
If Not API.IsRef(s) Then
|
| 97 |
Return NetResponse.RFC_TOKEN_INVALID
|
| 98 |
End If
|
| 99 |
|
| 100 |
Dim tokens As String() = s.Split(":"c)
|
| 101 |
Dim var As String = tokens(Scan0)
|
| 102 |
Dim size As Long = Scripting.CTypeDynamic(Of Long)(tokens(1))
|
| 103 |
|
| 104 |
If _sockets.ContainsKey(var) Then
|
| 105 |
Call _sockets.Remove(var)
|
| 106 |
End If
|
| 107 |
Call _sockets.Add(var, New MapStream.MSWriter(var, size))
|
| 108 |
|
| 109 |
Return NetResponse.RFC_OK
|
| 110 |
End Function
|
| 111 |
|
| 112 |
<Protocol(API.Protocols.Destroy)>
|
| 113 |
Private Function __destroy(CA As Long, request As RequestStream, remote As System.Net.IPEndPoint) As RequestStream
|
| 114 |
Dim var As String = request.GetUTF8String
|
| 115 |
|
| 116 |
If _sockets.ContainsKey(var) Then
|
| 117 |
Dim x = _sockets(var)
|
| 118 |
|
| 119 |
Call _sockets.Remove(var)
|
| 120 |
Call x.Free
|
| 121 |
|
| 122 |
Return NetResponse.RFC_OK
|
| 123 |
Else
|
| 124 |
Return NetResponse.RFC_TOKEN_INVALID
|
| 125 |
End If
|
| 126 |
End Function
|
| 127 |
End Class
|
| 128 |
End Namespace
|