Skip to content

Commit

Permalink
Fix: 2625 v4 -- IDL socket 0 issue and partial revert of PR #2620 (#2635
Browse files Browse the repository at this point in the history
)

* Fix: 2625 - IDL only by replace keyword_set()

* Fix: 2625 - Integrity check when add connection

* Fix: 2625 v4 - update debian packaging for IDL

* Fix: 2625 - correct typo in comment

* Fix: 2625 v4 - mdsdisconnect now correctly passes connection ID to the C library, mdsipshr

* Fix: 2625 v4 - more explanation of why mds_keyword_set() is needed

* Fix: 2625 v4 - revert PR 2620 connection.py change

* Fix: 2625 v4 -- add new IDL file to package for RHEL / Rocky

---------

Co-authored-by: Mark Winkel <mwinkel@psfc.mit.edu>
  • Loading branch information
mwinkel-dev and Mark Winkel committed Oct 9, 2023
1 parent 1408827 commit 138a468
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 17 deletions.
1 change: 1 addition & 0 deletions deploy/packaging/debian/idl.noarch
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
./usr/local/mdsplus/idl/mdsevent.pro
./usr/local/mdsplus/idl/mdsgetmsg.pro
./usr/local/mdsplus/idl/mdsidlimage.pro
./usr/local/mdsplus/idl/mds_keyword_set.pro
./usr/local/mdsplus/idl/mdsisclient.pro
./usr/local/mdsplus/idl/mdslogin.pro
./usr/local/mdsplus/idl/mdsopen.pro
Expand Down
1 change: 1 addition & 0 deletions deploy/packaging/redhat/idl.noarch
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
./usr/local/mdsplus/idl/mdsgetmsg.pro
./usr/local/mdsplus/idl/mdsidlimage.pro
./usr/local/mdsplus/idl/mdsisclient.pro
./usr/local/mdsplus/idl/mds_keyword_set.pro
./usr/local/mdsplus/idl/mdslogin.pro
./usr/local/mdsplus/idl/mdsopen.pro
./usr/local/mdsplus/idl/mdsput.pro
Expand Down
10 changes: 10 additions & 0 deletions idl/mds_keyword_set.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; This function detects if an optional keyword is present, regardless of value.
; IDL's keyword_set() only detects non-zero optional keywords (see Issue 2625).
; So replace it with this function that also handles zero.
function mds_keyword_set,socket=socket
if (n_elements(socket) gt 0) then begin
return, 1
endif else begin
return, 0
endelse
end
8 changes: 5 additions & 3 deletions idl/mdsconnect.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ function sockmin
end

function mds$socket,quiet=quiet,status=status,socket=socket
forward_function mds_keyword_set
status = 1
sockmin=sockmin()
sock=sockmin-1
if (keyword_set(socket)) then $
if (mds_keyword_set(socket=socket)) then $
if (socket ge sockmin) then $
return, socket
defsysv,'!MDS_SOCKET',exists=old_sock
Expand Down Expand Up @@ -152,8 +153,9 @@ end


pro mdsconnect,host,status=status,quiet=quiet,port=port,socket=socket
forward_function mds_keyword_set
on_error,2
if (not keyword_set(socket)) then $
if (not mds_keyword_set(socket=socket)) then $
mdsdisconnect,/quiet
if n_elements(port) ne 0 then begin
setenv_,'mdsip='+strtrim(port,2)
Expand All @@ -165,7 +167,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 mds_keyword_set(socket=socket) then $
!MDS_SOCKET = sock $
else $
socket = sock
Expand Down
8 changes: 5 additions & 3 deletions idl/mdsdisconnect.pro
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
pro mdsdisconnect,status=status,quiet=quiet, socket=socket
forward_function mds_keyword_set
forward_function mds$socket, MdsIPImage
image = MdsIPImage()
status = 1
if keyword_set(socket) then $
if mds_keyword_set(socket=socket) then $
sock = socket $
else $
sock = mds$socket(status=status,quiet=quiet)
if status then begin
status = call_external(image,'DisconnectFromMds',sock,value=[1b])
; IDL's AUTO_GLUE feature requires a C / C++ compiler on the system
status = call_external(image,'DisconnectFromMds',sock,value=[1b], /AUTO_GLUE)
if (status eq 0) then status = 1 else status = 0
if not keyword_set(socket) then $
if not mds_keyword_set(socket=socket) then $
!MDS_SOCKET = -1l
endif
return
Expand Down
17 changes: 12 additions & 5 deletions idl/mdsisclient.pro
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
function mdsisclient,socket=socket
if (keyword_set(socket)) then $
if (socket ge 0) then $
return, 1 $
else $
return, 0
forward_function mds_keyword_set

; If optional socket provided, use it
if (mds_keyword_set(socket=socket)) then $
if (socket ge 0) then $
return, 1 $
else $
return, 0

; Otherwise use the last socket
defsysv,'!MDS_SOCKET',exists=mdsClient
if (mdsClient) then begin
value= (!MDS_SOCKET ge 0)
return,value

; Went awry, so return INVALID_CONNECTION_ID
endif else begin
defsysv,'!MDS_SOCKET',-1
return,0
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));
c->id = id;
pthread_mutex_unlock(&lock);
c->state |= CON_INLIST;
Expand Down
6 changes: 1 addition & 5 deletions python/MDSplus/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,12 @@ def get(self, exp, *args, **kwargs):
args = kwargs['arglist']
timeout = kwargs.get('timeout', -1)
num = len(args)+1

exp = 'serializeout(`('+exp+'))'

exp = _ver.tobytes(exp)
_exc.checkStatus(_SendArg(self.conid, 0, 14, num,
len(exp), 0, 0, ctypes.c_char_p(exp)))
for i, arg in enumerate(args):
self._send_arg(arg, i+1, num)
retSerialized = self._get_answer(timeout)
return retSerialized.deserialize()
return self._get_answer(timeout)


class Connection(object):
Expand Down

0 comments on commit 138a468

Please sign in to comment.