Skip to content
Permalink
Browse files

Add support for initializing and shutting down networking.

This updates compinfo to use the new functions.
  • Loading branch information...
alesliehughes committed Jun 16, 2010
1 parent e4a8bbe commit b6c0c0ed8f475f7924e642589b10f41cea9be14f
Showing with 55 additions and 10 deletions.
  1. +27 −10 compinfo.c
  2. +25 −0 libdrqueue/communications.c
  3. +3 −0 libdrqueue/communications.h
@@ -46,6 +46,12 @@ int main (int argc,char *argv[]) {
struct computer *computer;
int ncomputers;
enum operation op = OP_NONE;
int nRet = 0;

if(network_initialize() != 0) {
fprintf (stderr,"Could not initialize the network: %s\n", drerrno_str());
return 1;
}

while ((opt = getopt (argc,argv,"lndc:vh")) != -1) {
switch (opt) {
@@ -57,7 +63,7 @@ int main (int argc,char *argv[]) {
break;
case 'v':
show_version (argv);
exit (0);
goto cleanup;
case 'l':
op = OP_LIST;
break;
@@ -67,20 +73,23 @@ int main (int argc,char *argv[]) {
case '?':
case 'h':
usage();
exit (1);
nRet = 1;
goto cleanup;
}
}

if ((op == OP_NONE)) {
usage ();
exit (1);
nRet = 1;
goto cleanup;
}

set_default_env();

if (!common_environment_check()) {
fprintf (stderr,"Error checking the environment: %s\n",drerrno_str());
exit (1);
nRet = 1;
goto cleanup;
}

switch (op) {
@@ -90,14 +99,16 @@ int main (int argc,char *argv[]) {
case OP_LIST:
if ((ncomputers = request_computer_list (&computer,CLIENT)) == -1) {
fprintf (stderr,"ERROR: While trying to request the computer list: %s\n",drerrno_str());
exit (1);
nRet = 1;
goto cleanup;
}
print_computers (computer,ncomputers);
break;
case OP_NUMBER:
if ((ncomputers = request_computer_list (&computer,CLIENT)) == -1) {
fprintf (stderr,"ERROR: While trying to request the computer list: %s\n",drerrno_str());
exit (1);
nRet = 1;
goto cleanup;
}
printf ("%i\n",ncomputers);
break;
@@ -107,20 +118,26 @@ int main (int argc,char *argv[]) {
computer_init(computer);
if (!computer) {
fprintf (stderr,"ERROR: Not enough memory\n");
exit (1);
nRet = 1;
goto cleanup;
}
if (!request_comp_xfer(icomp,computer,CLIENT)) {
fprintf (stderr,"ERROR: While trying to request the computer transfer: %s\n",drerrno_str());
exit (1);
nRet = 1;
goto cleanup;
}
print_computer_details (computer);
} else {
fprintf (stderr,"You need to specify the computer id using -c <computer_id>\n");
exit(1);
nRet = 1;
goto cleanup;
}
}

exit (0);
cleanup:
network_shutdown();

return nRet;
}

void print_computers (struct computer *computer, int ncomputers) {
@@ -1268,3 +1268,28 @@ dr_socket_write (int fd, char *buf, uint32_t len) {

return nSent;
}

int network_initialize()
{
int iResult = 0;
#ifdef _WIN32
WSADATA wsaData;

// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0) {
drerrno = DRE_NETWORKINIT;
log_auto(L_ERROR, "WSAStartup failed: %d\n", iResult);
return 1;
}
#endif
return iResult;
}

int network_shutdown()
{
#ifdef _WIN32
return WSACleanup();
#endif
return 0;
}
@@ -79,4 +79,7 @@ int recv_string (int sfd, char **str);
int send_blocked_host_list (int sfd, struct blocked_host *bh, uint32_t size, int do_checksize);
int recv_blocked_host_list (int sfd, struct blocked_host **bh, uint32_t *size, int do_checksize);

int network_initialize();
int network_shutdown();

#endif /* _COMMUNICATIONS_H_ */

0 comments on commit b6c0c0e

Please sign in to comment.
You can’t perform that action at this time.