All pastes #2133945 Raw Edit

Stuff

public text v1 · immutable
#2133945 ·published 2012-03-30 11:32 UTC
rendered paste body
    public static class SocketExtensions
    {
        static SocketManager IO;

        static SocketExtensions() {
            IO = new SocketManager();
            IO.Start();
        }

        public static void QueueTimeout(this Socket socket, TimeSpan dueTime, Action action) {
            IO.QueueTimeout(dueTime, action);
        }

        public static void QueueAccept(this Socket socket, SocketAcceptTask task) {
            task.Socket = socket;
            IO.QueueAccept(task);
        }

        public static void QueueConnect(this Socket socket, SocketConnectTask task) {
            task.Socket = socket;
            IO.QueueConnect(task);
        }

        public static void QueueDisconnect(this Socket socket, SocketDisconnectTask task) {
            task.Socket = socket;
            IO.QueueDisconnect(task);
        }

        public static void QueueSend(this Socket socket, byte[] buffer) {
            QueueSend(socket, buffer, 0, buffer.Length);
        }

        public static void QueueSend(this Socket socket, byte[] buffer, int offset, int count) {
            QueueSend(socket, new SocketSendTask(buffer, offset, count));
        }

        public static void QueueSend(this Socket socket, SocketSendTask task) {
            task.Socket = socket;
            IO.QueueWrite(task);
        }

        public static void QueueReceive(this Socket socket, SocketReceiveTask task) {
            task.Socket = socket;
            IO.QueueRead(task);
        }


        public static void Destroy(this Socket socket) {
            if (socket != null) {
                try {
                    socket.Close(100);
#if !MONO
                    socket.Dispose();
#endif
                }
                catch { }
            }
        }
    }