예제 #1
0
 /// <summary>
 /// Write data to the socket
 /// </summary>
 /// <param name="sock">socket object</param>
 /// <param name="data">data to write</param>
 public static void Write(this IGranadosSocket sock, DataFragment data)
 {
     if (data.Length > 0)
     {
         sock.Write(data.Data, data.Offset, data.Length);
     }
 }
예제 #2
0
        /// <summary>
        /// Sends a packet.
        /// </summary>
        /// <param name="packet">a packet object.</param>
        public void Send(PacketType packet)
        {
            BeforeSend(packet);
            lock (_syncSend) {
                if (_disconnected)
                {
#if DEBUG_SYNCHRONOUSPACKETHANDLER
                    System.Diagnostics.Debug.WriteLine("(blocked) <-- [{0}]", new object[] { GetMessageName(packet) });
#endif
                    return;
                }

#if DEBUG_SYNCHRONOUSPACKETHANDLER
                System.Diagnostics.Debug.WriteLine("S <-- [{0}]", new object[] { GetMessageName(packet) });
#endif
                _socket.Write(GetPacketImage(packet));
            }
        }
예제 #3
0
        /// <summary>
        /// Send a packet then receive a response.
        /// </summary>
        /// <param name="data">a packet to be sent</param>
        /// <returns>a packet received</returns>
        /// <exception cref="SSHException">unprocessed incoming packet exists</exception>
        public DataFragment SendAndWaitResponse(DataFragment data)
        {
            lock (_sync) {
                if (data.Length > 0)
                {
                    // queue must have no items
                    if (_queue.Count > 0)
                    {
                        Exception err = _queue.Peek() as Exception;
                        if (err != null)
                        {
                            ClearQueue();
                            throw err;
                        }
                        throw new SSHException("Unexpected incoming packet");
                    }
                    _socket.Write(data);
                }

                return(WaitResponse());
            }
        }