]> andersk Git - moira.git/blobdiff - lib/mr_connect.c
fix up so it works properly
[moira.git] / lib / mr_connect.c
index fde4e9f2555815e1f72d094e532d8d8cb3dc90c4..ab0da959a32a43ef661b6af809611ab570d2fb71 100644 (file)
@@ -4,82 +4,77 @@
  *     $Header$
  *
  *     Copyright (C) 1987 by the Massachusetts Institute of Technology
+ *     For copying and distribution information, please see the file
+ *     <mit-copyright.h>.
  *     
  *     This routine is part of the client library.  It handles
- * creating a connection to the sms server.
+ *     creating a connection to the sms server.
  */
 
 #ifndef lint
 static char *rcsid_sms_connect_c = "$Header$";
 #endif lint
 
-#include <gdb.h>
+#include <mit-copyright.h>
 #include "sms_private.h"
 
 /*
  * Open a connection to the sms server.
  */
 
-int sms_connect()
+int sms_connect(server)
+char *server;
 {
-       gdb_init();             /* Harmless if called twice. */
-       /* 
-        * should do a hesiod call to find the sms machine name & service
-        * number/name.
-        */
-
-       _sms_conn = start_server_connection(SMS_GDB_SERV, "XXX"); 
-       /* XXX gdb doesn't give real return codes. Can we trust errno?*/
-       if (_sms_conn == NULL) {
-               perror("gdb_connect");
-               return SMS_CANT_CONNECT;
-       }
-       return 0;
+    extern int errno;
+       
+    if (!sms_inited) sms_init();
+    if (_sms_conn) return SMS_ALREADY_CONNECTED;
+               
+    /* 
+     * XXX should do a hesiod call to find the sms machine name & service
+     * number/name.
+     */
+    errno = 0;
+    if (!server || (strlen(server) == 0))
+      server = SMS_GDB_SERV;
+    _sms_conn = start_server_connection(server, ""); 
+    if (_sms_conn == NULL)
+       return errno;
+    if (connection_status(_sms_conn) == CON_STOPPED) {
+       register status = connection_errno(_sms_conn);
+       if (!status) status = SMS_CANT_CONNECT;
+       sms_disconnect();
+       return status;
+    }
+    return 0;
 }
        
 int sms_disconnect()
 {
-       if (!_sms_conn) {
-               return SMS_NOT_CONNECTED;
-       }
-       /* Is this guaranteed NOT to fail?? I don't believe it, but.. */
-       _sms_conn = sever_connection(_sms_conn);
-       return 0;
+    CHECK_CONNECTED;
+    _sms_conn = sever_connection(_sms_conn);
+    return 0;
 }
 
 int sms_noop()
 {
-       int status;
-       struct sms_params *parms;
-
-       if (!_sms_conn) {
-               return SMS_NOT_CONNECTED;
-       }
+    int status;
+    sms_params param_st;
+    struct sms_params *params = NULL;
+    struct sms_params *reply = NULL;
 
-       if (!sms_call_op)
-               sms_call_op = create_operation();
-
-       parms = (struct sms_params *) malloc(sizeof(*parms));
+    CHECK_CONNECTED;
+    params = &param_st;
+    params->sms_version_no = sending_version_no;
+    params->sms_procno = SMS_NOOP;
+    params->sms_argc = 0;
+    params->sms_argl = NULL;
+    params->sms_argv = NULL;
        
-       parms->procno = SMS_NOOP;
-       parms->argc = 0;
-
-       gdb_inop(sms_call_op, sms_start_call, &parms, sms_abort_call);
-       gdb_qop(_sms_conn, CON_OUTPUT, sms_call_op);
-
-       gdb_inop(sms_recv_op, sms_start_recv, &reply, sms_abort_recv);
-       gdb_qop(_sms_conn, CON_INPUT, sms_recv_op);
-
-       /* Block until operation done. */
-       gdb_cmpo(sms_call_op);
-       gdb_cmpo(sms_recv_op);
+    if ((status = sms_do_call(params, &reply)) == 0)
+       status = reply->sms_status;
+       
+    sms_destroy_reply(reply);
 
-       /* Look at results */
-       if (OP_STATUS(sms_recv_op) != OP_COMPLETE) {
-               return SMS_ABORTED;
-       }
-       /* should look at return code from server.. */
-       return 0;
+    return status;
 }
-
-       
This page took 0.040527 seconds and 4 git commands to generate.