Giter Site home page Giter Site logo

tcpclient's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tcpclient's Issues

(使用rt_malloc/rt_free)在select_handle中收到数据时clear end,会出现数组越界

res = read(thiz->pipe_read_fd, pipe_buff, BUFF_SIZE);的返回值为1024,且pipe buff和sock buff相连,pipe_buff[res] = '\0';会修改sock buff的magic header,导致rt_free时产生异常

static void select_handle(rt_tcpclient_t *thiz, char *pipe_buff, char *sock_buff)
{
    fd_set fds;
    rt_int32_t max_fd = 0, res = 0;

    max_fd = MAX_VAL(thiz->sock_fd, thiz->pipe_read_fd) + 1;
    FD_ZERO(&fds);

    while (1)
    {
        FD_SET(thiz->sock_fd, &fds);
        FD_SET(thiz->pipe_read_fd, &fds);

        res = select(max_fd, &fds, RT_NULL, RT_NULL, RT_NULL);

        /* exception handling: exit */
        EXCEPTION_HANDLE(res, "select handle", "error", "timeout");

        /* socket is ready */
        if (FD_ISSET(thiz->sock_fd, &fds))
        {
            res = recv(thiz->sock_fd, sock_buff, BUFF_SIZE, 0);

            /* exception handling: exit */
            EXCEPTION_HANDLE(res, "socket recv handle", "error", "TCP disconnected");

            /* have received data, clear the end */
            sock_buff[res] = '\0';

            RX_CB_HANDLE(sock_buff, res);

            EXIT_HANDLE(sock_buff);
        }

        /* pipe is read */
        if (FD_ISSET(thiz->pipe_read_fd, &fds))
        {
            /* read pipe */
            res = read(thiz->pipe_read_fd, pipe_buff, BUFF_SIZE);

            /* exception handling: exit */
            EXCEPTION_HANDLE(res, "pipe recv handle", "error", "");

            /* have received data, clear the end */
            pipe_buff[res] = '\0';

            /* write socket */
            send(thiz->sock_fd, pipe_buff, res, 0);

            /* exception handling: warning */
            EXCEPTION_HANDLE(res, "socket write handle", "error", "warning");

            EXIT_HANDLE(pipe_buff);
        }
    }
exit:
    rt_free(pipe_buff);
    rt_free(sock_buff);
}

closesocket 与 select 返回值的问题

使用sal+dfs中的select

应用线程主动closesocket 时,select返回0,但select设置超时后也返回0,这两者怎么区分?
(ps:closesocket 过N久后,select也会返回1,表示一个可读事件,读取recv返回0,表示断开)

使用lwip中的select(即关闭sal和dfs组件)

应用线程主动closesocket 时,select返回1,代表有一个可读事件,读取recv返回0,表示断开。

粘包问题

多个线程同时往pipe中写入数据,而发送数据读取pipe中的数据进行发送,那是否存在多包数据粘包在一起发送的情况呢?

临界资源保护

  1. 关闭socket clinet时,两个thread线程也访问了这个handle,不安全。
  2. 多线程的这种操作socket方式不建议

内存泄漏

在tcpclient.c中,342行(pipe_buff[res] = '\0';)这句话,当res=BUFF_SIZE时,写操作会超出内存边界,导致(free(pipe_buff);)失败,报错内容(to free a bad data block: mem: 0x2001708c, used flag: 1, magic code: 0x1e00),需要屏蔽342行,第325行(sock_buff[res] = '\0';)也可能导致同样的问题。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.