Esempio n. 1
0
        private void OnReceive(IAsyncResult asyncResult)
        {
            Socket s = (Socket)asyncResult.AsyncState;

            try {
                int byteCount = s.EndReceive(asyncResult);
                if (byteCount > 0)
                {
                    UpdateAcitivty();

                    byte[] buffer = mRecvBuffer;
                    if (mEncoder != null)
                    {
                        mEncoder.DecodeIncomingPacket(this, ref buffer, ref byteCount);
                    }

                    lock (mBuffer) {
                        mBuffer.Enqueue(buffer, 0, byteCount);
                    }

                    //mMessagePump.OnReceive(this);
                    lock (mMessagePump) {
                        //Core.Set();
                        mMessagePump.HandleReceive(this);
                    }

                    lock (mAsyncLock) {
                        mAsyncState &= ~AsyncNetState.Pending;

                        if ((mAsyncState & AsyncNetState.Paused) == 0)
                        {
                            try {
                                InternalBeginReceive();
                            } catch (Exception ex) {
                                ExceptionHandler.Trace(ex);
                                Dispose(false);
                            }
                        }
                    }
                }
                else
                {
                    Dispose(false);
                }
            } catch (Exception ex) {
                ServerConsole.ErrorLine(ex.Message);
                ServerConsole.ErrorLine(ex.StackTrace);
                //ServerConsole.ErrorLine(Tools.CleanExcepionStacktrace(ex.StackTrace));
                Dispose(false);
            }
        }
Esempio n. 2
0
        private void OnReceive(IAsyncResult asyncResult)
        {
            Socket s = (Socket)asyncResult.AsyncState;

            try {
                int byteCount = s.EndReceive(asyncResult);
                if (byteCount > 0)
                {
                    UpdateAcitivty();

                    byte[] buffer = mRecvBuffer;
                    if (mEncoder != null)
                    {
                        mEncoder.DecodeIncomingPacket(this, ref buffer, ref byteCount);
                    }

                    lock (mBuffer)
                        mBuffer.Enqueue(buffer, 0, byteCount);

                    mMessagePump.OnReceive(this);

                    lock ( mAsyncLock ) {
                        mAsyncState &= ~AsyncNetState.Pending;

                        if ((mAsyncState & AsyncNetState.Paused) == 0)
                        {
                            try {
                                InternalBeginReceive();
                            } catch (Exception ex) {
                                ExceptionHandler.Trace(ex);
                                Dispose(false);
                            }
                        }
                    }
                }
                else
                {
                    Dispose(false);
                }
            } catch {
                Dispose(false);
            }
        }
Esempio n. 3
0
		protected void OnReceive(IAsyncResult asyncResult) {
			var s = (Socket)asyncResult.AsyncState;

			try {
				int byteCount = s.EndReceive(asyncResult);
				if (byteCount > 0) {
					UpdateAcitivty();

					byte[] buffer = mRecvBuffer;
					if (mEncoder != null) {
						mEncoder.DecodeIncomingPacket(this, ref buffer, ref byteCount);
					}

					lock (mBuffer)
						mBuffer.Enqueue(buffer, 0, byteCount);

					mMessagePump.OnReceive(this);

					lock (mAsyncLock) {
						mAsyncState &= ~AsyncNetState.Pending;

						if ((mAsyncState & AsyncNetState.Paused) == 0) {
							try {
								InternalBeginReceive();
							} catch (Exception ex) {
								Dispose(false);
								throw;
							}
						}
					}
				} else {
					Dispose(false);
				}
			} catch {
				Dispose(false);
			}
		}
Esempio n. 4
0
		private void OnReceive(IAsyncResult asyncResult) {
			Socket s = (Socket)asyncResult.AsyncState;

			try {
				int byteCount = s.EndReceive(asyncResult);
				if (byteCount > 0) {
					UpdateAcitivty();

					byte[] buffer = mRecvBuffer;
					if (mEncoder != null)
						mEncoder.DecodeIncomingPacket(this, ref buffer, ref byteCount);

					lock (mBuffer) {
						mBuffer.Enqueue(buffer, 0, byteCount);
					}

					//mMessagePump.OnReceive(this);
					lock (mMessagePump) {
						//Core.Set();
						mMessagePump.HandleReceive(this);
					}

					lock (mAsyncLock) {
						mAsyncState &= ~AsyncNetState.Pending;

						if ((mAsyncState & AsyncNetState.Paused) == 0) {
							try {
								InternalBeginReceive();
							} catch (Exception ex) {
								ExceptionHandler.Trace(ex);
								Dispose(false);
							}
						}
					}
				} else {
					Dispose(false);
				}
			} catch (Exception ex) {
				ServerConsole.ErrorLine(ex.Message);
				ServerConsole.ErrorLine(ex.StackTrace);
				//ServerConsole.ErrorLine(Tools.CleanExcepionStacktrace(ex.StackTrace));
				Dispose(false);
			}
		}