Beispiel #1
0
    private static void send_cb(IAsyncResult ar)
    {
        netsocket obj = (netsocket)ar.AsyncState;

        if (obj.sendq.Count == 0)
        {
            return;
        }
        byte[] a = (byte[])obj.sendq.Dequeue();
        obj.dosend(a);
        return;
    }
Beispiel #2
0
    private static void connect_cb(IAsyncResult ar)
    {
        netsocket obj = (netsocket)ar.AsyncState;

        obj._status = CONNECTED;
        Debug.Log("Connect:" + obj.s.Connected);
        obj.dorecv();
        if (obj.sendq.Count > 0)
        {
            byte[] a = (byte[])obj.sendq.Dequeue();
            obj.dosend(a);
        }
        return;
    }
Beispiel #3
0
 public static int lcreate(IntPtr L)
 {
     try {
         int count = LuaDLL.lua_gettop(L);
         if (count == 0)
         {
             netsocket obj = new netsocket();
             ToLua.Push(L, obj);
             return(1);
         }
         else
         {
             return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: netsocket.create"));
         }
     } catch (Exception e) {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #4
0
    private static void recv_cb(IAsyncResult ar)
    {
        netsocket obj  = (netsocket)ar.AsyncState;
        int       read = obj.s.EndReceive(ar);

        if (read > 0)
        {
            lock (obj.readstream) {
                obj.readstream.write(obj.buffer, 0, read);
            }
            obj.dorecv();
        }
        else
        {
            Debug.Log("RecvCB: Disconnect");
            obj._status = DISCONNECT;
            obj.s.Close();
            lock (obj.readstream) {
                obj.readstream.clear();
            }
        }
    }