dup2 trouble

Stan zylog at club-internet.fr
Fri Mar 12 15:19:23 UTC 2004


Hi,

I working upon a board similar to mcf5206elite.
It seems that dup2 don't work properly.
Does anyone can try this :

void serverTCP() {
 int des_socket,
     acp_socket,fd;
 struct sockaddr_in srv;
 char * devname;
 int i=1, n=0;
 int size_adr;
 char buff[80];

 if ((des_socket=socket(PF_INET,SOCK_STREAM,0))<0) {
  perror("serverTCP:socket");
  rtems_task_delete(RTEMS_SELF);
 };
 setsockopt(des_socket,SOL_SOCKET,0,&i,sizeof(i));
 memset(&srv,0,sizeof(srv));
 srv.sin_family=AF_INET;
 srv.sin_port=htons(3000);
 size_adr=sizeof(srv);
 if ((bind(des_socket,(struct sockaddr *)&srv,size_adr))<0) {
  perror("serverTCP:bind");
         close(des_socket);
  rtems_task_delete(RTEMS_SELF);
 };
 if ((listen(des_socket,5))<0) {
  perror("serverTCP:listen");
         close(des_socket);
  rtems_task_delete(RTEMS_SELF);
 };
 do {
   acp_socket=accept(des_socket,(struct sockaddr*)&srv,&size_adr);
   if (acp_socket<0) {
  perror("serverTCP:accept");
  break;
   };

  /* for redirect stdout over socket */
    fd = dup2(acp_socket, STDOUT_FILENO);


   do{

  n = read(acp_socket, buff, sizeof(buff));
  if(n){
      if(strstr(buff,"exit")) break;

   if(strstr(buff,"echo")){

    printf("show message...\n"); /* don't write over socket ! */
    rtems_task_wake_after(1);

   }
      n = sprintf(buff, "Server V1.00 [%d]\n", i++);
      write(acp_socket, buff, n);
  }else printf("error on socket\n");
     }while(1);
     close(acp_socket);

 } while(1);
 close(des_socket);

}
/***********************************************************/

dup2 don't return -1, but printf don't send the message via the socket.

An idea ?
Thanks a lot.

Stan.






More information about the users mailing list