From da2c77ff22b7fc4d05a453748800cd7ac7991aa2 Mon Sep 17 00:00:00 2001 From: Stephen Lane-Walsh Date: Tue, 3 Oct 2023 14:06:15 -0400 Subject: [PATCH] Revert "Fix: 2625 v2 - only change IDL for socket 0 issue (#2628)" This reverts commit 443018ead5ae95bb74e89da924d795de5ab449a7. --- idl/dsql.pro | 12 ++++-------- idl/mdsconnect.pro | 12 ++++-------- idl/mdsdisconnect.pro | 6 ++---- idl/mdsisclient.pro | 15 +++------------ idl/mdssql.pro | 21 +++++++-------------- idl/mdsvalue.pro | 2 -- idl/set_database.pro | 9 +++------ mdstcpip/mdsipshr/Connections.c | 2 +- 8 files changed, 24 insertions(+), 55 deletions(-) diff --git a/idl/dsql.pro b/idl/dsql.pro index 18311c36d1..c5a0eb129c 100644 --- a/idl/dsql.pro +++ b/idl/dsql.pro @@ -230,8 +230,7 @@ if (debug) then $ ; now execute the query ; !!! if it is a string it is a database error ; -socket_var = !MDSDB_SOCKET -count = mdsvalue(expr, socket=socket_var) +count = mdsvalue(expr, socket=!MDSDB_SOCKET) sz = size(count) if (sz(n_elements(sz)-2) eq 7) then begin @@ -255,8 +254,7 @@ endif else begin if (debug) then $ print, 'Working on arg ', i arg = 'a'+string(i, format="(I3.3)") - socket_var = !MDSDB_SOCKET - val = MDSVALUE("_"+arg,socket=socket_var,/QUIET) + val = MDSVALUE("_"+arg,socket=!MDSDB_SOCKET,/QUIET) ok = evaluate(arg + ' = val') if (ok eq "OK") then status = 1L else status = 0L if (debug) then $ @@ -277,10 +275,8 @@ endif else begin ; ; free all the tdi variables returned by DSQL ; - if (not debug) then begin - socket_var = !MDSDB_SOCKET - dummy = MdsValue("DeAllocate('_A%%%')",socket=socket_var,/QUIET) - endif + if (not debug) then $ + dummy = MdsValue("DeAllocate('_A%%%')",socket=!MDSDB_SOCKET,/QUIET) ; ; return the number of row ; diff --git a/idl/mdsconnect.pro b/idl/mdsconnect.pro index ffd0cf755c..77e5fea488 100644 --- a/idl/mdsconnect.pro +++ b/idl/mdsconnect.pro @@ -13,9 +13,7 @@ function mds$socket,quiet=quiet,status=status,socket=socket status = 1 sockmin=sockmin() sock=sockmin-1 - ; The arg_present() only works if the optional keyword argument - ; is bound to a regular variable in the calling code. - if (arg_present(socket)) then $ + if (keyword_set(socket)) then $ if (socket ge sockmin) then $ return, socket defsysv,'!MDS_SOCKET',exists=old_sock @@ -139,7 +137,7 @@ pro mds$disconnect,status=status,quiet=quiet if status then begin status = call_external(MdsIPImage(),'IdlDisconnectFromMds',sock,value=[1b]) if (status eq 0) then status = 1 else status = 0 - !MDS_SOCKET = 0l ; Is this correct? Should it be -1? + !MDS_SOCKET = 0l endif return end @@ -155,9 +153,7 @@ end pro mdsconnect,host,status=status,quiet=quiet,port=port,socket=socket on_error,2 - ; The arg_present() only works if the optional keyword argument - ; is bound to a regular variable in the calling code. - if (not arg_present(socket)) then $ + if (not keyword_set(socket)) then $ mdsdisconnect,/quiet if n_elements(port) ne 0 then begin setenv_,'mdsip='+strtrim(port,2) @@ -169,7 +165,7 @@ pro mdsconnect,host,status=status,quiet=quiet,port=port,socket=socket sockmin=sockmin() if (sock ge sockmin) then begin status = 1 - if not arg_present(socket) then $ + if not keyword_set(socket) then $ !MDS_SOCKET = sock $ else $ socket = sock diff --git a/idl/mdsdisconnect.pro b/idl/mdsdisconnect.pro index 1a683ba116..f91140f1a2 100644 --- a/idl/mdsdisconnect.pro +++ b/idl/mdsdisconnect.pro @@ -2,16 +2,14 @@ pro mdsdisconnect,status=status,quiet=quiet, socket=socket forward_function mds$socket, MdsIPImage image = MdsIPImage() status = 1 - ; The arg_present() only works if the optional keyword argument - ; is bound to a regular variable in the calling code. - if arg_present(socket) then $ + if keyword_set(socket) then $ sock = socket $ else $ sock = mds$socket(status=status,quiet=quiet) if status then begin status = call_external(image,'DisconnectFromMds',sock,value=[1b]) if (status eq 0) then status = 1 else status = 0 - if not arg_present(socket) then $ + if not keyword_set(socket) then $ !MDS_SOCKET = -1l endif return diff --git a/idl/mdsisclient.pro b/idl/mdsisclient.pro index 23b719ddd7..198d2a303d 100644 --- a/idl/mdsisclient.pro +++ b/idl/mdsisclient.pro @@ -1,22 +1,13 @@ -; This function is used to confirm a valid connection has been established. -function mdsisclient,socket=socket_var - -; For arg_present() to work, the optional keyword argument must be bound -; to a regular variable. It will not work if bound to a system variable -; such as !MDS_SOCKET. Refer to issue #2625 for more details. -if (arg_present(socket_var)) then $ - if (socket_var ge 0) then $ +function mdsisclient,socket=socket +if (keyword_set(socket)) then $ + if (socket ge 0) then $ return, 1 $ else $ return, 0 - - ; If no connection specified, then assume using the most recent one. defsysv,'!MDS_SOCKET',exists=mdsClient if (mdsClient) then begin value= (!MDS_SOCKET ge 0) return,value - - ; If things have gone awry, indicate an INVALID_CONNECTION_ID endif else begin defsysv,'!MDS_SOCKET',-1 return,0 diff --git a/idl/mdssql.pro b/idl/mdssql.pro index 818a73f326..be7b76c488 100644 --- a/idl/mdssql.pro +++ b/idl/mdssql.pro @@ -54,8 +54,7 @@ pro MDSDbDisconnect defsysv, '!MDSDB_SOCKET', -1 defsysv, '!MDSDB_HOST', '' endif - socket_var = !MDSDB_SOCKET - MdsDisconnect, socket=socket_var + MdsDisconnect, socket=!MDSDB_SOCKET !MDSDB_SOCKET = -1 !MDSDB_HOST = "" end @@ -80,8 +79,7 @@ end pro set_database, dbname, status=status, quiet=quiet,debug=debug status = dbinfo(dbname, host, name, user, pass, mdshost) MDSDbconnect, mdshost - socket_var = !MDSDB_SOCKET - status = mdsvalue("DBLogin($, $, $)", host, user, pass, socket=socket_var) + status = mdsvalue("DBLogin($, $, $)", host, user, pass, socket=!MDSDB_SOCKET) if (not status) then begin if not (keyword_set(quiet)) then begin Message, "Error logging on to DbHost "+host, /continue @@ -90,8 +88,7 @@ pro set_database, dbname, status=status, quiet=quiet,debug=debug endelse return endif -; socket_var = !MDSDB_SOCKET -; status = mdsvalue("SetDatabase('"+ name+"')", socket=socket_var) +; status = mdsvalue("SetDatabase('"+ name+"')", socket=!MDSDB_SOCKET) status = dsql('USE ?', name) if (status ne 0) then begin if not (keyword_set(quiet)) then begin @@ -245,8 +242,7 @@ if (debug) then $ ; now execute the query ; !!! if it is a string it is a database error ; -socket_var = !MDSDB_SOCKET -count = mdsvalue(expr, socket=socket_var) +count = mdsvalue(expr, socket=!MDSDB_SOCKET) sz = size(count) if (sz(n_elements(sz)-2) eq 7) then begin @@ -273,8 +269,7 @@ endif else begin if (debug) then $ print, 'Working on arg ', i arg = 'a'+string(i, format="(I3.3)") - socket_var = !MDSDB_SOCKET - cmd = arg+' = MDSVALUE("_'+arg+'",socket=socket_var)' + cmd = arg+' = MDSVALUE("_'+arg+'",socket=!MDSDB_SOCKET)' status = execute(cmd) if (debug) then $ print, "got back "+arg @@ -292,10 +287,8 @@ endif else begin ; ; free all the tdi variables returned by DSQL ; - if (not debug) then begin - socket_var = !MDSDB_SOCKET - dummy = MdsValue("DeAllocate('_A%%%')",socket=socket_var) - endif + if (not debug) then $ + dummy = MdsValue("DeAllocate('_A%%%')",socket=!MDSDB_SOCKET) ; ; return the number of row ; diff --git a/idl/mdsvalue.pro b/idl/mdsvalue.pro index 9daf5a8d24..3be635413e 100644 --- a/idl/mdsvalue.pro +++ b/idl/mdsvalue.pro @@ -46,8 +46,6 @@ function MdsValue,expression,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13,arg14,arg15,arg16,quiet=quiet,status=status,socket=socket - ; Note that Issue #2625 requires the optional "socket" keyword argument - ; to be bound to a regular variable in the calling code. forward_function mdsIsClient,mdsIdlImage,mds$socket,MdsIPImage,evaluate MdsCheckArg,expression,type="STRING",name="expression" diff --git a/idl/set_database.pro b/idl/set_database.pro index cd9d451e65..ee4a16c41f 100644 --- a/idl/set_database.pro +++ b/idl/set_database.pro @@ -408,10 +408,8 @@ pro MDSDbDisconnect defsysv, '!MDSDB_SOCKET', -1 defsysv, '!MDSDB_HOST', '' endif - if !MDSDB_SOCKET ne -1 then begin - socket_var = !MDSDB_SOCKET - MdsDisconnect, socket=socket_var - endif + if !MDSDB_SOCKET ne -1 then $ + MdsDisconnect, socket=!MDSDB_SOCKET !MDSDB_SOCKET = -1 !MDSDB_HOST = "" end @@ -441,8 +439,7 @@ pro set_database, dbname, status=status, quiet=quiet,debug=debug, reset=reset, f if (status eq 0) then $ return MDSDbconnect, mdshost - socket_var = !MDSDB_SOCKET - status = mdsvalue("dblogin($, $, $)", host, user, pass, socket=socket_var) + status = mdsvalue("dblogin($, $, $)", host, user, pass, socket=!MDSDB_SOCKET) if (not status) then begin if not (keyword_set(quiet)) then begin Message, mdsvalue('dsc:MdsSql->GetDBMsgText_dsc()'), /continue diff --git a/mdstcpip/mdsipshr/Connections.c b/mdstcpip/mdsipshr/Connections.c index c9b0ec6c46..297614d235 100644 --- a/mdstcpip/mdsipshr/Connections.c +++ b/mdstcpip/mdsipshr/Connections.c @@ -471,7 +471,7 @@ int AddConnection(Connection *c) do { id++; // find next free id - } while ((id == INVALID_CONNECTION_ID) || _FindConnection(id, NULL, MDSIPTHREADSTATIC_VAR)); + } while (id == INVALID_CONNECTION_ID && _FindConnection(id, NULL, MDSIPTHREADSTATIC_VAR)); c->id = id; pthread_mutex_unlock(&lock); c->state |= CON_INLIST;