Esempio n. 1
0
        public void ReleaseConnection(Connection conn)
        {
            if (!conn.InUse)
            {
                var header = new FDFSHeader(0, Consts.FDFS_PROTO_CMD_QUIT, 0);
                var buffer = header.ToByte();
                conn.GetStream().Write(buffer, 0, buffer.Length);
                conn.GetStream().Close();
            }

            conn.Close();

            lock ((_inUse as ICollection).SyncRoot)
            {
                _inUse.Remove(conn);
            }
            _autoEvent.Set();
        }
Esempio n. 2
0
        public virtual byte[] GetResponse()
        {
            if (Connection == null)
            {
                Connection = ConnectionManager.GetTrackerConnection();
            }

            try
            {
                //打开
                Connection.OpenConnection();

                var stream       = Connection.GetStream();
                var headerBuffer = Header.ToByte();

                stream.Write(headerBuffer, 0, headerBuffer.Length);
                stream.Write(Body, 0, Body.Length);

                var header = new FDFSHeader(stream);
                if (header.Status != 0)
                {
                    throw new FDFSException(string.Format("Get Response Error,Error Code:{0}", header.Status));
                }

                var body = new byte[header.Length];
                if (header.Length != 0)
                {
                    stream.Read(body, 0, (int)header.Length);
                }

                return(body);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                //关闭
                //Connection.Close();
                Connection.ReleaseConnection();
            }
        }