Functions

gs_stage_file.c File Reference

#include "utility.h"
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "comm_data.h"
#include "comm_basics.h"
#include "comm_encode.h"
#include "general.h"
Include dependency graph for gs_stage_file.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Detailed Description

This program will stage a file from one server to another. The usage is: GS_stage_file <file_name> <server_name> [server_port] )

Definition in file gs_stage_file.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Entry point for GS_killserver.

Parameters:
argc -- arg count
argv -- array of command line args
Returns:
EXIT_SUCCESS on success, EXIT_FAILURE on error.

Definition at line 32 of file gs_stage_file.c.

{
  char *host, *filename, *remote_file_info;
  gs_server_t *gs_server = NULL;
  int server_sock, tag, port;
  struct hostent *hp;
  char cid[CID_LEN];
  ipaddr_t ipaddr;

  memset(cid, 0xFF, CID_LEN);

  if(argc < 3) {
    fprintf(stderr, "Usage: GS_stage_file <file name> <server name> [server port]\n");
    exit(EXIT_FAILURE);
  }

  filename = argv[1];
  host = argv[2];

  if(argc == 4)
    port = atoi(argv[3]);
  else
    port = GRIDSOLVE_SERVER_PORT_DEFAULT;
  
  DBGPRINTF("Connecting to host %s port %d\n", host, port);

  if ((hp = gethostbyname(host)) == NULL) {
    errno = errno_socket();
    ERRPRINTF("Could not gethostbyname for %s (errno %d) \n", host, errno);
    perror("gethostbyname()");
    return INVALID_SOCKET;
  }

  memcpy((void *) &ipaddr, hp->h_addr_list[0], sizeof(ipaddr));
  
  /* all ones will match any component ID */
  memset(cid, 0xFF, CID_LEN);

  server_sock = gs_connect_to_host(cid, ipaddr, port, 0, 0);

  if(server_sock < 0) {
    fprintf(stderr, "Unsuccessful (connecting server)\n");
    gs_server_free(gs_server);
    exit(EXIT_FAILURE);
  }

  if((gs_send_tag(server_sock, GS_PROT_STORE_FILE) < 0) ||
     (gs_send_string(server_sock, VERSION) < 0)) {
    fprintf(stderr, "Unsuccessful (sending tag to Server)\n");
    gs_server_free(gs_server);
    exit(EXIT_FAILURE);
  }

  if(gs_recv_tag(server_sock, &tag) < 0) {
    fprintf(stderr, "Error communicating with server.\n");
    exit(EXIT_FAILURE);
  }

  if(tag != GS_PROT_OK) {
    if(tag == GS_PROT_VERSION_MISMATCH)
      fprintf(stderr, "Error: Server is an incompatible version\n");
    else
      fprintf(stderr, "Error: Server refused with code %d\n", tag);
    exit(EXIT_FAILURE);
  }

  remote_file_info="foo";

  if(gs_send_string(server_sock, remote_file_info) < 0) {
    fprintf(stderr, "Unsuccessful (Sending remote_file_info)\n");
    gs_server_free(gs_server);
    exit(EXIT_FAILURE);
  }

  if(gs_send_arg_from_file(server_sock, filename) < 0) {
    fprintf(stderr, "Error sending from file '%s'\n", filename);
    gs_server_free(gs_server);
    exit(EXIT_FAILURE);
  }
  
  gs_server_free(gs_server);

  exit(EXIT_SUCCESS);
}

Here is the call graph for this function: