Changeset 87288e in git


Ignore:
Timestamp:
Aug 19, 2010, 12:31:11 PM (14 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '5b153614cbc72bfa198d75b1e9e33dab2645d9fe')
Children:
d693da2907d20603c7b413016aea28f4c3807267
Parents:
0f4cea42a23350c26fd4412d806c25ba0c6974cd
Message:
ssi:tcp host:port

git-svn-id: file:///usr/local/Singular/svn/trunk@13125 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/ssiLink.cc

    r0f4cea r87288e  
    587587    }
    588588  }
    589   else
     589  else /*l->name=NULL*/
    590590  {
    591591    // tcp mode
     
    616616      }
    617617      while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
    618       Print("waiting on port %d\n", portno);mflush();
     618      //Print("waiting on port %d\n", portno);mflush();
    619619      listen(sockfd,5);
    620620      char* cli_host = (char*)omAlloc(256);
     
    635635      sprintf(ssh_command,"ssh %s %s -q --batch --link=ssi --MPhost=%s --MPport=%d &",cli_host,path,ser_host,portno);
    636636      system(ssh_command);
    637       Print("client on %s started:%s\n",cli_host,path);
     637      //Print("client on %s started:%s\n",cli_host,path);
    638638      clilen = sizeof(cli_addr);
    639639      newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
     
    643643        return TRUE;
    644644      }
    645       PrintS("client accepted\n");
     645      //PrintS("client accepted\n");
    646646      d->fd_read = newsockfd;
    647647      d->fd_write = newsockfd;
     
    659659 
    660660      sscanf(l->name,"%255[^:]:%d",host,&portno);
    661       Print("connect to host %s, port %d\n",host,portno);mflush();
     661      //Print("connect to host %s, port %d\n",host,portno);mflush();
    662662      if (portno!=0)
    663663      {
     
    668668        memset((char *) &serv_addr, 0, sizeof(serv_addr));
    669669        serv_addr.sin_family = AF_INET;
    670         bcopy((char *)server->h_addr,
    671               (char *)&serv_addr.sin_addr.s_addr,
     670        memcpy((char *)&serv_addr.sin_addr.s_addr,
     671              (char *)server->h_addr,
    672672              server->h_length);
    673673        serv_addr.sin_port = htons(portno);
    674674        if (connect(sockfd,(sockaddr*)&serv_addr,sizeof(serv_addr)) < 0)
    675675        { WerrorS("ERROR connecting"); return TRUE; }
    676         PrintS("connected\n");mflush();
     676        //PrintS("connected\n");mflush();
    677677        d->f_read=fdopen(sockfd,"r");
    678678        d->fd_read=sockfd;
     
    731731  if (d!=NULL)
    732732  {
    733     if (d->pid!=0) { fprintf(d->f_write,"99\n");fflush(d->f_write); }
     733    if ((strcmp(l->mode,"tcp")==0)
     734    || (strcmp(l->mode,"fork")==0))
     735    {
     736      fprintf(d->f_write,"99\n");fflush(d->f_write);
     737    }
    734738    if (d->f_read!=NULL) fclose(d->f_read);
    735739    if (d->f_write!=NULL) fclose(d->f_write);
     
    992996/* return 0 on success, >0 else*/
    993997{
    994   int sockfd, portno, n;
    995   struct sockaddr_in serv_addr;
    996   struct hostent *server;
    997  
    998   portno = atoi(port);
    999   if (portno!=0)
    1000   {
    1001     sockfd = socket(AF_INET, SOCK_STREAM, 0);
    1002     if (sockfd < 0) { WerrorS("ERROR opening socket"); exit(0); }
    1003     server = gethostbyname(host);
    1004     if (server == NULL) {  WerrorS("ERROR, no such host");  exit(0); }
    1005     memset((char *) &serv_addr, 0, sizeof(serv_addr));
    1006     serv_addr.sin_family = AF_INET;
    1007     memcpy((char *)&serv_addr.sin_addr.s_addr,
    1008           (char *)server->h_addr,
    1009           server->h_length);
    1010     serv_addr.sin_port = htons(portno);
    1011     if (connect(sockfd,(sockaddr*)&serv_addr,sizeof(serv_addr)) < 0)
    1012     { WerrorS("ERROR connecting"); exit(0); }
    1013     si_link l;
    1014     if (slInit(l,"ssi:tcp")) WerrorS("error slInit");
    1015     ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
    1016     d->f_read=fdopen(sockfd,"r");
    1017     d->fd_read=sockfd;
    1018     d->f_write=fdopen(sockfd,"w");
    1019     d->fd_write=sockfd;
    1020     l->data=d;
    1021     SI_LINK_SET_RW_OPEN_P(l);
    1022     loop
    1023     {
    1024       PrintS("start read\n");
    1025       leftv h=ssiRead1(l); /*contains an exit.... */
    1026       if (feErrors != NULL && *feErrors != '\0')
    1027       {
    1028         // handle errors:
    1029         PrintS(feErrors); /* currently quite simple */
    1030         *feErrors = '\0';
    1031       }
    1032       PrintS("start write\n");
    1033       ssiWrite(l,h);
    1034       h->CleanUp();
    1035       omFreeBin(h, sleftv_bin);
    1036     }
    1037     /* never reached*/
    1038     exit(0);
    1039   }
     998  si_link l=(si_link) omAlloc0Bin(sip_link_bin);
     999  char *buf=(char*)omAlloc(256);
     1000  sprintf(buf,"ssi:connect %s:%s",host,port);
     1001  slInit(l, buf);
     1002  slOpen(l,SI_LINK_OPEN);
     1003  SI_LINK_SET_RW_OPEN_P(l);
     1004  loop
     1005  {
     1006    leftv h=ssiRead1(l); /*contains an exit.... */
     1007    if (feErrors != NULL && *feErrors != '\0')
     1008    {
     1009      // handle errors:
     1010      PrintS(feErrors); /* currently quite simple */
     1011      *feErrors = '\0';
     1012    }
     1013    ssiWrite(l,h);
     1014    h->CleanUp();
     1015    omFreeBin(h, sleftv_bin);
     1016  }
     1017  /* never reached*/
    10401018  exit(0);
    10411019}
Note: See TracChangeset for help on using the changeset viewer.