0

我的目标平台(运行在uCOS)上出现问题,write()似乎不允许我将数据写入连接的客户端套接字(端口 21),它返回一个负数并设置errno11解释为No more processes- 我不确定这意味着什么。描述问题的示例函数如下所示:

  #include <stdio.h>
  #include <errno.h>
  #include <string.h>
  #include <unistd.h>
  #include <fcntl.h>
  #include <arpa/inet.h>

  char *host = "10.10.100.1";
  int port = 21;
  int control_fd = -1;
  int code;
  char *hostname;
  static struct sockaddr_in hisctladdr;
  static struct sockaddr_in myctladdr;
  int len; 

char *test(char *host, int port);

char *test(char *host, int port) {
  static char hostnamebuf[256];
  fd_set          L_rset;
  struct timeval  L_timeout;
  unsigned char   mychar;
  char            buf[10] ={'A','U','T','H',' ','T','L','S','\0','\n'};
  int             L_cmdLength;
  int             L_read;
  int         len;
  int         rv;
  int         i;

  if (inet_aton(host, &hisctladdr.sin_addr))
  {
    hisctladdr.sin_family = AF_INET;
    hisctladdr.sin_port = htons(port);
    strncpy(hostnamebuf, host, sizeof(hostnamebuf));
    hostnamebuf[sizeof(hostnamebuf) - 1] = 0;
  }
  else
  {
    printf("Ftp::test IP dot format required\n");
    code = -1;
    return (NULL);
  }
  hostname = hostnamebuf;
  control_fd = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
  if (control_fd < 0)
  {
    printf("Ftp::test socket\n");
    code = -1;
    close(control_fd);
    control_fd = -1;
    return (NULL);
  }

  if (connect(control_fd, (struct sockaddr *)&hisctladdr, sizeof(hisctladdr)) < 0) {
    if (errno != EINPROGRESS)
    {
      printf("Ftp::test : connect failure\n");
    }
  }

  printf("Ftp::test : connected\n");

  len = sizeof(struct sockaddr_in);
  if (getsockname(control_fd, (struct sockaddr *)&myctladdr, &len) < 0)
  {
   printf("Ftp::test Error getsockname errno %d\n", errno);
    code = -1;
    close(control_fd);
    control_fd = -1;
    return (NULL);
  }
  L_timeout.tv_sec = 10;
  L_timeout.tv_usec = 0;
  // retrieve welcome message from server
  FD_ZERO(&L_rset);
  FD_SET(control_fd,&L_rset);  
  rv = select(control_fd + 1, &L_rset, NULL, NULL, &L_timeout);
  if (rv < 0){
    printf("Ftp::test error reading from socket %d\n", rv);
    return (NULL);
  } else if (rv >0) {
    for(i = 0; i < 2 &&FD_ISSET(control_fd, &L_rset);i++){
        L_read = recv(control_fd, (char *)&mychar, 1, 0);
        printf("received %c 0x%x\n",mychar,mychar);
    }
    printf("Ftp::test connection to server established!\n");
  } else {
    printf("No data received from server within 10 seconds, timeout!\n");
    return (NULL);
  }
  L_cmdLength = strlen(buf);
  printf("Ftp::test : write (%d, %s, %d)\n",control_fd, buf, L_cmdLength);
  rv = write(control_fd, buf, L_cmdLength);
  if (rv >= 0)
    printf("Ftp::test : sent %dBytes\n", rv);
  else 
    printf("Ftp:test : error writing data, errno %d %s\n",errno, strerror(errno));
  return (NULL);
}
void main(void){
  test(host,port);
}

“常规主机”完成功能Ftp::test : sent 8Bytes而我的目标完成功能Ftp:test : error writing data, errno 11 No more processes

在目标上运行此函数时完成标准输出捕获:

Ftp::test : connected
received 2 0x32
received 2 0x32
Ftp::test connection to server established!
Ftp::test : write (14, AUTH TLS, 8)
Ftp:test : error writing data, errno 11 No more processes
4

0 回答 0