public static void SendBind(Socket destination, Pipe pipe, bool increaseSequenceNumber) { if(increaseSequenceNumber) destination.IncreaseSequenceNumber(); var command = new BindCommand(destination, pipe); SendCommand(command); }
internal static Pipe ConnectEndpoint(Socket connectSocket, string address) { lock (s_endpointsSync) { Socket boundSocket; int connectHighWatermark = connectSocket.Options.SendHighWatermark; int bindHighWatermark = connectSocket.Options.ReceiveHighwatermark; if (s_endpoints.TryGetValue(address, out boundSocket)) { // Increment the command sequence number of the peer so that it won't // get deallocated until "bind" command is issued by the caller. // The subsequent 'bind' has to be called with inc_seqnum parameter // set to false, so that the seqnum isn't incremented twice. boundSocket.IncreaseSequenceNumber(); if (connectHighWatermark != 0 && boundSocket.Options.ReceiveHighwatermark != 0) connectHighWatermark += boundSocket.Options.ReceiveHighwatermark; if (bindHighWatermark != 0 && boundSocket.Options.SendHighWatermark != 0) bindHighWatermark += boundSocket.Options.SendHighWatermark; } Pipe connectPipe; Pipe bindPipe; Pipe.CreatePair(connectSocket, boundSocket ?? connectSocket, bindHighWatermark, connectHighWatermark, out connectPipe, out bindPipe); if (boundSocket == null) { // The peer doesn't exist yet so we don't know whether // to send the identity message or not. To resolve this, // we always send our identity and drop it later if // the peer doesn't expect it. Frame identity = new Frame(0); identity.Identity = true; connectPipe.TryWrite(ref identity); connectPipe.Flush(); connectSocket.IncreaseSequenceNumber(); AddPendingConnection(connectSocket, address, connectPipe, bindPipe); } else { // If required, send the identity of the local socket to the peer. if (boundSocket.Options.ReceiveIdentity) { Frame identity = new Frame(0); identity.Identity = true; connectPipe.TryWrite(ref identity); connectPipe.Flush(); } // If required, send the identity of the peer to the local socket. if (connectSocket.Options.ReceiveIdentity) { Frame identity = new Frame(0); identity.Identity = true; bindPipe.TryWrite(ref identity); bindPipe.Flush(); } // Attach remote end of the pipe to the peer socket. Note that peer's // sequence nubmer was incremented in find endpoint function. We don't need it // increased here. CommandDispatcher.SendBind(boundSocket, bindPipe, false); } return connectPipe; } }
private static void ConnectInprocSockets(Socket boundSocket, PendingConnection connection) { boundSocket.IncreaseSequenceNumber(); connection.BindPipe.SlotId = boundSocket.SlotId; // If bound socket doesn't receive identity we need to read from the pipe as we already // insert the message while creating the pipe pair if (!boundSocket.Options.ReceiveIdentity) { Frame frame; connection.BindPipe.TryRead(out frame); frame.Close(); } int inHighWatermark = 0; int outHighWatermark = 0; if (boundSocket.Options.SendHighWatermark != 0 && connection.Socket.Options.ReceiveHighwatermark != 0) inHighWatermark = boundSocket.Options.SendHighWatermark + connection.Socket.Options.ReceiveHighwatermark; if (boundSocket.Options.ReceiveHighwatermark != 0 && connection.Socket.Options.SendHighWatermark != 0) outHighWatermark = boundSocket.Options.ReceiveHighwatermark + connection.Socket.Options.SendHighWatermark; // Set the highwatermarks now as before the bound highwater marks was missing connection.ConnectPipe.SetHighWatermarks(inHighWatermark,outHighWatermark); connection.BindPipe.SetHighWatermarks(outHighWatermark, inHighWatermark); BindCommand bindCommand = new BindCommand(boundSocket, connection.BindPipe); boundSocket.Process(bindCommand); CommandDispatcher.SendInprocConnected(connection.Socket); if (connection.Socket.Options.ReceiveIdentity) { Frame identity = new Frame(); identity.Identity = true; connection.BindPipe.TryWrite(ref identity); connection.BindPipe.Flush(); } }