コード例 #1
0
ファイル: Rinex3NavData.cpp プロジェクト: JC5005/GPSTk
      // Outputs the record to the FFStream \a s.
   void Rinex3NavData::reallyPutRecord(FFStream& ffs) const
      throw(exception, FFStreamError, StringException)
   {

      try {
         Rinex3NavStream& strm = dynamic_cast<Rinex3NavStream&>(ffs);

         putPRNEpoch(strm);

         // put 3 data records
         for(int i=1; i<=3; i++) putRecord(i, strm);

         // SBAS and GLO only have 3 records
         if(satSys == "S" || satSys == "R") return;

         // GPS QZS BDS and GAL have 7 records, put 4-7
         if(satSys == "G" || satSys == "C" || satSys == "E" || satSys == "J")
            for(int i=4; i<=7; i++) putRecord(i, strm);
      }
      catch(exception& e) {
         FFStreamError fse(string("std::exception: ") + e.what());
         GPSTK_THROW(fse);
      }
      catch(FFStreamError& fse) { GPSTK_RETHROW(fse); }
      catch(StringException& se) { GPSTK_RETHROW(se); }

   }  // End of method 'Rinex3NavData::reallyPutRecord(FFStream& ffs)'
コード例 #2
0
ファイル: backup.c プロジェクト: chmoder/tdcross_vulcan
int main(void)
{
    char               *db_name = "srecDB.fql";
    struct DB          *db;
    char               print_buf[BUFSIZ];
    /*struct Node        db[4];*/
    int                quitter = 1;
    int                recieved = 0;
    char               buf[ BUFSIZ ];
    int                sd, sd_current/*, cc, fromlen, tolen*/;
    socklen_t          addrlen;
    struct sockaddr_in sin;
    struct sockaddr_in pin;
 

    /* Get an internet domain socket */
    if ( ( sd = socket( AF_INET, SOCK_STREAM, 0) ) == -1 )
    {
        perror( "socket");
        exit( 1 );
    }

    /* Complete the socket structure */
    memset( &sin, 0, sizeof(sin) );
    sin.sin_family = AF_INET;
    sin.sin_addr.s_addr = INADDR_ANY;
    sin.sin_port = htons( PORT );

    /* Bind the socket to the port number */
    if ( bind( sd, ( struct sockaddr *) &sin, sizeof( sin ) ) == -1) 
    {
        perror( "bind" );
        exit( 1 );
    }

    /* Listen for clients that want to connect.         */
    /* In a real "server" we would get a connection and */
    /* then "fork" or create a thread for that one, but */
    /* here we only handle one connection.              */
    if ( listen( sd, 5 ) == -1 ) 
    {
        perror( "listen" );
        exit( 1 );
    }

    /* Wait for a client connection, then accept it. */
    addrlen = sizeof(pin); 
    if ( ( sd_current = accept( sd, ( struct sockaddr *)&pin, &addrlen ) ) == -1 )
    {
        perror( "accept");
        exit( 1 );
    }

    /* Let's show the incoming stuff just for fun. */
    /*printf( "Coming from port %d\n", ntohs( pin.sin_port ) );*/

    /* If this is a server that needs to keep taking messages */
    /* from the client, then put a "while" loop here to keep  */
    /* reading data. The easy way to do this is to have the   */
    /* client send "exit" or some special string to terminate */
    /* the "while" loop. Otherwise you tend to get SIGPIPE or */
    /* other errors from the "recv" and "send" calls.         */

    /* Open database file*/
    db = openDb(db_name);

    /* get a message from the client */
    while((recieved = recv(sd_current, buf, sizeof(buf), 0)) > 0 && quitter)
    {
        char delims[] = " ";
        char *request = NULL;
        char *data = NULL; 

        request = strtok(buf, delims);
        data = strtok(NULL, delims);

        if(!strcmp(request, "stop"))
        {
            closeDb(db, db_name);
            quitter = 0;
        }
        else if(!strcmp(request, "get"))
        {
            getRecord(db, data, print_buf, sd_current);
        }
        else if(!strcmp(request, "put"))
        {
            putRecord(db, data);
        }
        else if(!strcmp(request, "delete"))
        {
            deleteRecord(db, data);
        }
    }

    /* close up both sockets */
    close( sd_current ); 
    close( sd );

    return( 0 );
}