Exemplo n.º 1
0
        public DocumentServer(string hostName, int port, string directory, int bufferSize = 4096 * 12)
        {
            _version = Util.GetIndexVersionListInChronologicalOrder(directory)[0];

            var dataFn = Path.Combine(directory, _version.Version + ".rdb");

            _data = new FileStream(
                dataFn,
                FileMode.Open,
                FileAccess.Read,
                FileShare.ReadWrite,
                bufferSize,
                FileOptions.RandomAccess);

            _reader = new StreamBlockReader(
                _data, _version.KeyIndexOffset + _version.KeyIndexSize);

            IPHostEntry ipHostInfo    = Dns.GetHostEntryAsync(hostName).Result;
            IPAddress   ipAddress     = ipHostInfo.AddressList[1];
            IPEndPoint  localEndPoint = new IPEndPoint(ipAddress, port);

            _listener = new Socket(AddressFamily.InterNetwork,
                                   SocketType.Stream, ProtocolType.Tcp);

            _listener.Bind(localEndPoint);
            _listener.Listen(10);

            _cache = new ConcurrentDictionary <long, byte[]>();
        }