Exemplo n.º 1
0
        public Lua.CharPtr Connect(Lua.CharPtr address, int port, pTimeout tm)
        {
            if (tcpSocket != null)
            {
                try
                {
                    int timeout = (int)tm.block * 1000;
                    if (timeout < 0)
                    {
                        timeout = 0;
                    }
#if !NETFX_CORE
                    tcpSocket.Connect(new DnsEndPoint(address.ToString(), port), timeout);
#else
                    //TODO:
#endif
                }
                catch (Exception e)
                {
                    return(address);
                }
            }

            /*else if(tcpSocketChannel != null)
             * {
             *      try
             *      {
             *              int timeout = (int) tm.block * 1000;
             *              if(timeout < 0)
             *                      timeout = 0;
             *              tcpSocketChannel.configureBlocking(true);
             *              boolean connected = tcpSocketChannel.connect(new InetSocketAddress(InetAddress.getByName(address.toString()), port));
             *              while(!tcpSocketChannel.finishConnect())
             *              {
             *                      Thread.sleep(50);
             *              }
             *              tcpSocketChannel.socket().setSoTimeout(timeout);
             *              tcpSocketChannel.socket().setKeepAlive(true);
             *              tcpSocketChannel.socket().setTcpNoDelay(true);
             *              //tcpSocketWriter = new BufferedWriter(new OutputStreamWriter(tcpSocketChannel.socket().getOutputStream()));
             *              if(cantSetNonBlocking)
             *              {
             *                      SetNonBlocking(cantSetNonBlockingValue);
             *                      cantSetNonBlocking = false;
             *              }
             *      }
             *      catch (Exception e)
             *      {
             *              return address;
             *      }
             * }*/
            return(null);
        }
Exemplo n.º 2
0
 public int Accept(out pSocket sockP, Object object1, Object object2, pTimeout tm)
 {
     /*if(listener != null)
      * {
      *      try
      *      {
      *              sockP.SetTcpSocket(listener.accept());
      *      }
      *      catch(Exception e)
      *      {
      *              return pIO.IO_UNKNOWN;
      *      }
      * }
      * else
      *      return pIO.IO_UNKNOWN;*/
     sockP = new pSocket(0);
     return(pIO.IO_DONE);
 }
Exemplo n.º 3
0
        public static int socket_recv(pSocket ps, Lua.CharPtr data, int count, out int got, pTimeout tm)
        {
            //p_socket ps, char *data, size_t count, size_t *got, p_timeout tm
            int err;

            got = 0;
            if (ps == null)
            {
                return(pIO.IO_CLOSED);
            }
            for (; ;)
            {
                int taken = ps.Recv(data, (int)count, 0);
                if (taken > 0)
                {
                    got = taken;
                    return(pIO.IO_DONE);
                }
                if (taken == 0 || taken == -1)
                {
                    return(pIO.IO_CLOSED);
                }
                //if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
            }
        }
Exemplo n.º 4
0
        public static int socket_send(pSocket ps, Lua.CharPtr data, int count, out int sent, pTimeout tm)
        {
            int err = 0;

            sent = 0;
            /* avoid making system calls on closed sockets */
            if (ps == null)
            {
                return(pIO.IO_CLOSED);
            }
            /* loop until we send something or we give up on error */
            for (; ;)
            {
                /* try to send something */
                int put = ps.Send(data, (int)count, 0, out err);
                /* if we sent something, we are done */
                if (put > 0)
                {
                    sent = put;
                    return(pIO.IO_DONE);
                }
                if (err > 0)
                {
                    return(err);
                }
                else
                {
                    return(0);
                }

                //if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err;
            }
            /* can't reach here */
            //return pIO.IO_UNKNOWN;
        }
Exemplo n.º 5
0
 public pTcp()
 {
     io  = new pIO();
     buf = new pBuffer();
     tm  = new pTimeout();
 }