Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions idl/dsql.pro
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ if (debug) then $
; now execute the query
; !!! if it is a string it is a database error
;
count = mdsvalue(expr, socket=!MDSDB_SOCKET)
socket_var = !MDSDB_SOCKET
count = mdsvalue(expr, socket=socket_var)

sz = size(count)
if (sz(n_elements(sz)-2) eq 7) then begin
Expand All @@ -254,7 +255,8 @@ endif else begin
if (debug) then $
print, 'Working on arg ', i
arg = 'a'+string(i, format="(I3.3)")
val = MDSVALUE("_"+arg,socket=!MDSDB_SOCKET,/QUIET)
socket_var = !MDSDB_SOCKET
val = MDSVALUE("_"+arg,socket=socket_var,/QUIET)
ok = evaluate(arg + ' = val')
if (ok eq "OK") then status = 1L else status = 0L
if (debug) then $
Expand All @@ -275,8 +277,10 @@ endif else begin
;
; free all the tdi variables returned by DSQL
;
if (not debug) then $
dummy = MdsValue("DeAllocate('_A%%%')",socket=!MDSDB_SOCKET,/QUIET)
if (not debug) then begin
socket_var = !MDSDB_SOCKET
dummy = MdsValue("DeAllocate('_A%%%')",socket=socket_var,/QUIET)
endif
;
; return the number of row
;
Expand Down
12 changes: 8 additions & 4 deletions idl/mdsconnect.pro
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ function mds$socket,quiet=quiet,status=status,socket=socket
status = 1
sockmin=sockmin()
sock=sockmin-1
if (keyword_set(socket)) then $
; 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 (socket ge sockmin) then $
return, socket
defsysv,'!MDS_SOCKET',exists=old_sock
Expand Down Expand Up @@ -137,7 +139,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
!MDS_SOCKET = 0l ; Is this correct? Should it be -1?
endif
return
end
Expand All @@ -153,7 +155,9 @@ end

pro mdsconnect,host,status=status,quiet=quiet,port=port,socket=socket
on_error,2
if (not keyword_set(socket)) then $
; 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 $
mdsdisconnect,/quiet
if n_elements(port) ne 0 then begin
setenv_,'mdsip='+strtrim(port,2)
Expand All @@ -165,7 +169,7 @@ pro mdsconnect,host,status=status,quiet=quiet,port=port,socket=socket
sockmin=sockmin()
if (sock ge sockmin) then begin
status = 1
if not keyword_set(socket) then $
if not arg_present(socket) then $
!MDS_SOCKET = sock $
else $
socket = sock
Expand Down
6 changes: 4 additions & 2 deletions idl/mdsdisconnect.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ pro mdsdisconnect,status=status,quiet=quiet, socket=socket
forward_function mds$socket, MdsIPImage
image = MdsIPImage()
status = 1
if keyword_set(socket) then $
; 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 $
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 keyword_set(socket) then $
if not arg_present(socket) then $
!MDS_SOCKET = -1l
endif
return
Expand Down
15 changes: 12 additions & 3 deletions idl/mdsisclient.pro
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
function mdsisclient,socket=socket
if (keyword_set(socket)) then $
if (socket ge 0) then $
; 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 $
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
Expand Down
21 changes: 14 additions & 7 deletions idl/mdssql.pro
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ pro MDSDbDisconnect
defsysv, '!MDSDB_SOCKET', -1
defsysv, '!MDSDB_HOST', ''
endif
MdsDisconnect, socket=!MDSDB_SOCKET
socket_var = !MDSDB_SOCKET
MdsDisconnect, socket=socket_var
!MDSDB_SOCKET = -1
!MDSDB_HOST = ""
end
Expand All @@ -79,7 +80,8 @@ end
pro set_database, dbname, status=status, quiet=quiet,debug=debug
status = dbinfo(dbname, host, name, user, pass, mdshost)
MDSDbconnect, mdshost
status = mdsvalue("DBLogin($, $, $)", host, user, pass, socket=!MDSDB_SOCKET)
socket_var = !MDSDB_SOCKET
status = mdsvalue("DBLogin($, $, $)", host, user, pass, socket=socket_var)
if (not status) then begin
if not (keyword_set(quiet)) then begin
Message, "Error logging on to DbHost "+host, /continue
Expand All @@ -88,7 +90,8 @@ pro set_database, dbname, status=status, quiet=quiet,debug=debug
endelse
return
endif
; status = mdsvalue("SetDatabase('"+ name+"')", socket=!MDSDB_SOCKET)
; socket_var = !MDSDB_SOCKET
; status = mdsvalue("SetDatabase('"+ name+"')", socket=socket_var)
status = dsql('USE ?', name)
if (status ne 0) then begin
if not (keyword_set(quiet)) then begin
Expand Down Expand Up @@ -242,7 +245,8 @@ if (debug) then $
; now execute the query
; !!! if it is a string it is a database error
;
count = mdsvalue(expr, socket=!MDSDB_SOCKET)
socket_var = !MDSDB_SOCKET
count = mdsvalue(expr, socket=socket_var)
sz = size(count)
if (sz(n_elements(sz)-2) eq 7) then begin

Expand All @@ -269,7 +273,8 @@ endif else begin
if (debug) then $
print, 'Working on arg ', i
arg = 'a'+string(i, format="(I3.3)")
cmd = arg+' = MDSVALUE("_'+arg+'",socket=!MDSDB_SOCKET)'
socket_var = !MDSDB_SOCKET
cmd = arg+' = MDSVALUE("_'+arg+'",socket=socket_var)'
status = execute(cmd)
if (debug) then $
print, "got back "+arg
Expand All @@ -287,8 +292,10 @@ endif else begin
;
; free all the tdi variables returned by DSQL
;
if (not debug) then $
dummy = MdsValue("DeAllocate('_A%%%')",socket=!MDSDB_SOCKET)
if (not debug) then begin
socket_var = !MDSDB_SOCKET
dummy = MdsValue("DeAllocate('_A%%%')",socket=socket_var)
endif
;
; return the number of row
;
Expand Down
2 changes: 2 additions & 0 deletions idl/mdsvalue.pro
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@


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"
Expand Down
9 changes: 6 additions & 3 deletions idl/set_database.pro
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,10 @@ pro MDSDbDisconnect
defsysv, '!MDSDB_SOCKET', -1
defsysv, '!MDSDB_HOST', ''
endif
if !MDSDB_SOCKET ne -1 then $
MdsDisconnect, socket=!MDSDB_SOCKET
if !MDSDB_SOCKET ne -1 then begin
socket_var = !MDSDB_SOCKET
MdsDisconnect, socket=socket_var
endif
!MDSDB_SOCKET = -1
!MDSDB_HOST = ""
end
Expand Down Expand Up @@ -439,7 +441,8 @@ pro set_database, dbname, status=status, quiet=quiet,debug=debug, reset=reset, f
if (status eq 0) then $
return
MDSDbconnect, mdshost
status = mdsvalue("dblogin($, $, $)", host, user, pass, socket=!MDSDB_SOCKET)
socket_var = !MDSDB_SOCKET
status = mdsvalue("dblogin($, $, $)", host, user, pass, socket=socket_var)
if (not status) then begin
if not (keyword_set(quiet)) then begin
Message, mdsvalue('dsc:MdsSql->GetDBMsgText_dsc()'), /continue
Expand Down
2 changes: 1 addition & 1 deletion mdstcpip/mdsipshr/Connections.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for tracking, this is fixed re: Timo's comments:
#2626 (comment)

c->id = id;
pthread_mutex_unlock(&lock);
c->state |= CON_INLIST;
Expand Down