Exemple #1
0
        int IEventHandler.Peek(BufferedSocket bufferedSocket, IByteBuffer msg, ref EndPoint ep)
        {
            Contract.Requires(ep != null);
            //Contract.Requires(bufferedSocket != null);

            return default(int);
        }
Exemple #2
0
 void IEventHelpers.RegisterSocketRead(IEvent e, BufferedSocket socket, IEventHandler protocol,
                                       ReadFunction callback)
 {
     //Contract.Requires(socket != null);
     Contract.Requires(protocol != null);
     Contract.Requires(callback != null);
 }
Exemple #3
0
        int IEventHandler.Read(BufferedSocket socket, IByteBuffer msg, ref EndPoint ep)
        {
            //Contract.Requires(socket != null);
            Contract.Requires(msg != null);
            Contract.Requires(ep != null);

            return default(int);
        }
 public void RegisterSocketAccept(BufferedSocket socket, Action<BufferedSocket> callback)
 {
     var thread = new Thread(() =>
                                 {
                                     try
                                     {
                                         socket.Socket.Blocking = true;
                                         while (socket.IsBound)
                                         {
                                             BufferedSocket newConnection = socket.Accept();
                                             //newConnection.Blocking = false;
                                             lock (this)
                                             {
                                                 Thread.BeginCriticalRegion();
                                                 callback(newConnection);
                                                 Thread.EndCriticalRegion();
                                             }
                                         }
                                     }
                                     catch (ThreadAbortException)
                                     {
                                         Console.WriteLine("Accept for socket Aborted");
                                         return;
                                     }
                                     catch (SocketException ex)
                                     {
                                         if (ex.ErrorCode == 10004)
                                         {
                                             Console.WriteLine("Accept for socket Aborted");
                                             return;
                                         }
                                         else
                                         {
                                             Console.WriteLine("Unknown exception in accept thread: " +
                                                               ex.Message);
                                         }
                                     }
                                 });
     thread.Name = "Socket Accept " + socket.LocalEndPointIp;
     _onAcceptSockets.Add(socket, thread);
     thread.Start();
 }
        public void RegisterSocketAccept(BufferedSocket socket, Action<BufferedSocket> callback)
        {
            #if DEBUG_VERBOSE
            Console.WriteLine("RegisterSocketAccept");
            #endif

            var handle = (int) socket.Handle;
            if (handle == -1)
            {
                Console.WriteLine("RegisterSocketWrite socket already closed");
                return;
            }
            if (!AddSocket(handle, EpollEvents.EPOLLIN))
            {
            }
            Action acceptHandle = () =>
                                      {
                                          BufferedSocket s2 = null;
                                          try
                                          {
                                              s2 = socket.Accept();
                                          }
                                          catch (Exception)
                                          {
                                              //TODO: unregister uing intger handle
                                              UnregisterSocketAccept(socket);
                                              return;
                                          }

                                          callback(s2);
                                      };

            if (_onAcceptSockets.ContainsKey(handle))
                _onAcceptSockets[handle] = acceptHandle;
            else
                _onAcceptSockets.Add(handle, acceptHandle);
        }
 public void UnregisterSocketWrite(BufferedSocket socket)
 {
     lock (this)
     {
         _onWriteSockets.Remove(socket);
     }
 }
 public void UpdateSocketAccept(BufferedSocket socket, Action<BufferedSocket> callback)
 {
     UnregisterSocketAccept(socket);
     RegisterSocketAccept(socket, callback);
 }
 public void UnregisterSocketAccept(BufferedSocket socket)
 {
     if (!_onAcceptSockets.ContainsKey(socket))
     {
         throw new ArgumentOutOfRangeException("socket", "BufferedSocket does not exist in accept list");
     }
     _onAcceptSockets[socket].Abort();
     _onAcceptSockets.Remove(socket);
 }
 public void UnregisterSocketRead(BufferedSocket socket)
 {
     lock (this)
     {
         _onReadSockets.Remove(socket);
     }
 }
 public void RegisterSocketWrite(BufferedSocket socket, Action callback)
 {
     lock (this)
     {
         _onWriteSockets.Add(socket, callback);
     }
 }
 public void UnregisterSocket(BufferedSocket socket)
 {
     lock (this)
     {
         if (_onReadSockets.ContainsKey(socket))
             _onReadSockets.Remove(socket);
         if (_onWriteSockets.ContainsKey(socket))
             _onWriteSockets.Remove(socket);
         if (_onAcceptSockets.ContainsKey(socket))
             _onAcceptSockets[socket].Abort();
     }
 }
Exemple #12
0
 void IEvent.RegisterSocketWrite(BufferedSocket socket, Action callback)
 {
     //Contract.Requires(socket != null);
     Contract.Requires(callback != null);
 }
 public void RegisterSocketRead(BufferedSocket socket, Action callback)
 {
     lock (this)
     {
     #if DEBUG
         if (_onReadSockets.ContainsKey(socket))
         {
             throw new Exception("Socket already added!");
         }
     #endif
         _onReadSockets.Add(socket, callback);
     }
 }
Exemple #14
0
 void IEvent.UnregisterSocket(BufferedSocket socket)
 {
     //Contract.Requires(socket != null);
 }
        public void UpdateSocketAccept(BufferedSocket socket, Action<BufferedSocket> callback)
        {
            var handle = (int) socket.Handle;
            if (handle == -1)
            {
                Console.WriteLine("UpdateSocketAccept socket already closed");
                return;
            }
            Action acceptHandle = () =>
                                      {
                                          BufferedSocket s2 = null;
                                          try
                                          {
                                              s2 = socket.Accept();
                                          }
                                          catch (Exception)
                                          {
                                              UnregisterSocketAccept(socket);
                                              return;
                                          }

                                          callback(s2);
                                      };

            if (_onAcceptSockets.ContainsKey(handle))
                _onAcceptSockets[handle] = acceptHandle;
        }
        public void UnregisterSocketWrite(BufferedSocket socket)
        {
            #if DEBUG_VERBOSE
            Console.WriteLine("UnregisterSocketWrite");
            #endif
            var handle = (int) socket.Handle;

            if (handle == -1)
            {
                //if (_onReadSockets.ContainsKey(socket.OldHandle))
                //    _onReadSockets.Remove(socket.OldHandle);
                Console.WriteLine("UnregisterSocketWrite socket already closed");
                return;
            }

            _onWriteSockets.Remove(handle);

            if (!RemoveSocket(handle, EpollEvents.EPOLLOUT))
            {
            }
        }
        public void UnregisterSocketAccept(BufferedSocket socket)
        {
            #if DEBUG_VERBOSE
            Console.WriteLine("UnregisterSocketAccept");
            #endif
            var handle = (int) socket.Handle;

            if (handle == -1)
            {
                //if (_onAcceptSockets.ContainsKey(socket.OldHandle))
                //    _onAcceptSockets.Remove(socket.OldHandle);
                Console.WriteLine("UnregisterSocketAccept socket already closed");
                return;
            }

            _onAcceptSockets.Remove(handle);
            _epoll.Delete(handle);
        }
 public void UnregisterSocket(BufferedSocket socket)
 {
     #if DEBUG_VERBOSE
     Console.WriteLine("UnregisterSocket");
     #endif
     var fd = (int) socket.Handle;
     if (_onReadSockets.ContainsKey(fd))
         UnregisterSocketRead(socket);
     if (_onWriteSockets.ContainsKey(fd))
         UnregisterSocketWrite(socket);
     if (_onAcceptSockets.ContainsKey(fd))
         UnregisterSocketAccept(socket);
 }
        public void RegisterSocketRead(BufferedSocket socket, Action callback)
        {
            #if DEBUG_VERBOSE
            Console.WriteLine("RegisterSocketRead");
            #endif
            var handle = (int) socket.Handle;
            if (handle == -1)
            {
                Console.WriteLine("RegisterSocketRead socket already closed");
                return;
            }

            if (!AddSocket(handle, EpollEvents.EPOLLIN))
            {
            }

            #if DEBUG
            if (_onReadSockets.ContainsKey(handle))
                Console.WriteLine("Already waiting on read from socket");
            #endif
            if (_onReadSockets.ContainsKey(handle))
                _onReadSockets[handle] = callback;
            else
                _onReadSockets.Add(handle, callback);
        }
Exemple #20
0
 void IEvent.RegisterSocketAccept(BufferedSocket socket, Action<BufferedSocket> callback)
 {
     //Contract.Requires(socket != null);
     Contract.Requires(callback != null);
 }