Example #1
0
int roadmap_io_write (RoadMapIO *io, const void *data, int length, int wait) {

   switch (io->subsystem) {

      case ROADMAP_IO_FILE:
         return roadmap_file_write (io->os.file, data, length);

      case ROADMAP_IO_NET:
         return roadmap_net_send (io->os.socket, data, length, wait);

      case ROADMAP_IO_PIPE:
         return roadmap_spawn_write_pipe (io->os.pipe, data, length);

      case ROADMAP_IO_NULL:
         return length; /* It's all done, since there is nothing to do. */
   }
   return -1;
}
Example #2
0
int roadmap_io_write_async (RoadMapIO *io, const void *data, int length) {
   
   switch (io->subsystem) {
      case ROADMAP_IO_NET:
#if defined(IPHONE_NATIVE) || defined(GTK) || defined(ANDROID)
         return roadmap_net_send_async( io->os.socket, data, length );
#else
         return roadmap_net_send (io->os.socket, data, length, 0); //Change this to async once implemented
#endif
      
      case ROADMAP_IO_FILE:
#ifndef QTMOBILITY
      case ROADMAP_IO_SERIAL:
#endif
      case ROADMAP_IO_PIPE:
         return -1;
         
      case ROADMAP_IO_NULL:
         return length; /* It's all done, since there is nothing to do. */
   }
   return -1;
}
RoadMapSocket roadmap_gpsd2_connect (const char *name) {

   RoadMapSocket socket = roadmap_net_connect ("tcp", name, 0, 2947, NULL);

   if (ROADMAP_NET_IS_VALID(socket)) {

      /* Start watching what happens. */

      static const char request[] = "w+\n";

      if (roadmap_net_send
            (socket, request, sizeof(request)-1, 1) != sizeof(request)-1) {

         roadmap_log (ROADMAP_WARNING, "Lost gpsd server session");
         roadmap_net_close (socket);

         return ROADMAP_INVALID_SOCKET;
      }
   }

   return socket;
}
Example #4
0
static int roadmap_httpcopy (RoadMapDownloadCallbacks *callbacks,
                             const char *source,
                             const char *destination) {

   RoadMapSocket fd;
   RoadMapFile file;
   int size;
   int loaded;
   int received;

   char buffer[ROADMAP_HTTP_MAX_CHUNK];


   fd = roadmap_net_connect("http_get", source, 80, NULL);
   if (!ROADMAP_NET_IS_VALID(fd)) return 0;
   if (roadmap_net_send(fd, "\r\n", 2, 0) == -1) return 0;

   received = sizeof(buffer);
   size = roadmap_http_decode_header
             (fd, buffer, &received, callbacks->error);
   if (size <= 0) {
      roadmap_net_close (fd);
      return 0; /* We did not get the size. */
   }

   if (! callbacks->size (size)) {
      roadmap_net_close (fd);
      return 0;
   }

   callbacks->progress (received);
   roadmap_file_remove (NULL, destination);
   file = roadmap_file_open(destination, "w");
   if (!ROADMAP_FILE_IS_VALID(file)) {
      roadmap_net_close (fd);
      return 0;
   }

   if (received > 0) {
      if (roadmap_file_write(file, buffer, received) != received) {
         callbacks->error ("Error writing data");
         goto cancel_download;
      }
   }
   loaded = received;

   while (loaded < size) {

      received = roadmap_net_receive (fd, buffer, sizeof(buffer));

      if (received <= 0) {
         callbacks->error ("Receive error after %d data bytes", loaded);
         goto cancel_download;
      }
      
      if (roadmap_file_write(file, buffer, received) != received) {
         callbacks->error ("Error writing data");
         goto cancel_download;
      }

      loaded += received;

      callbacks->progress (loaded);
   }

   if (loaded != size) {
      callbacks->error ("Receive error after %d data bytes", loaded);
      goto cancel_download;   
   }
   roadmap_net_close (fd);
   roadmap_file_close(file);

   return 1;

cancel_download:

   roadmap_file_close(file);
   roadmap_file_remove (NULL, destination);
   roadmap_net_close (fd);

   return 0;
}