internal byte[] GetResponseFromServer(SyncSocket clientSocket) { throw new ApplicationException(); // todo2[ak] //InProcSocket server = this.GetServerOfClient(clientSocket); //server.OnReceived(); }
internal void AcceptClientConnection(SyncSocket socket) { // todo1[ak] check args if (socket.TransportContext != this) { throw new ApplicationException(); // todo2[ak] } if (socket.Mode != SocketMode.None) { throw new ApplicationException(); // todo2[ak] } string address = socket.Address; SyncSocket listener; lock (_lock) { bool listening = _listeners.TryGetValue(address, out listener); if (!listening) { throw new ApplicationException(); // todo2[ak] } SyncSocket serverSocket = (SyncSocket)this.CreateSocket(); serverSocket.Assign(address); serverSocket.Mode = SocketMode.Reply; socket.Mode = SocketMode.Request; Connection con = new Connection(serverSocket, socket); List<Connection> list; bool haveAddress = _servers.TryGetValue(address, out list); if (!haveAddress) { list = new List<Connection>(); _servers.Add(address, list); } listener.OnClientAccepted(serverSocket); list.Add(con); } }
internal void RegisterListener(SyncSocket socket) { // todo1[ak] check args if (socket.TransportContext != this) { throw new ApplicationException(); // todo2[ak] } if (socket.Mode != SocketMode.None) { throw new ApplicationException(); // todo2[ak] } string address = socket.Address; if (address == null) { throw new ApplicationException(); // todo2[ak] } // todo1[ak] check address has form "inproc://..." lock (_lock) { bool alreadyListening = _listeners.ContainsKey(socket.Address); if (alreadyListening) { throw new ApplicationException(); // todo2[ak] } _listeners.Add(address, socket); socket.Mode = SocketMode.Listen; } }
public ISocket CreateSocket() { ISocket socket = new SyncSocket(this); return socket; }
internal Connection(SyncSocket serverSocket, SyncSocket clientSocket) { this.ServerSocket = serverSocket; this.ClientSocket = clientSocket; }
private SyncSocket GetServerOfClient(SyncSocket clientSocket) { string address = clientSocket.Address; lock (_lock) { List<Connection> list; bool have = _servers.TryGetValue(address, out list); if (!have) { throw new ApplicationException(); // todo2[ak] } Connection con = list.SingleOrDefault(c => c.ClientSocket == clientSocket); // todo1[ak] optimize? if (con == null) { throw new ApplicationException(); // todo2[ak] } SyncSocket server = con.ServerSocket; return server; } }
internal void SendRequestToServer(SyncSocket clientSocket, byte[] buffer) { // todo1[ak] check args lock (_lock) { SyncSocket server = this.GetServerOfClient(clientSocket); server.SetReceivedBuffer(buffer); } }