Skip to content

Commit efb5196

Browse files
committed
Fix issue #99
Add timezone offsets for mqmetric calculations
1 parent 1d65851 commit efb5196

File tree

6 files changed

+30
-14
lines changed

6 files changed

+30
-14
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Changelog
22
Newest updates are at the top of this file.
33

4-
## April XX 2019
4+
## April 23 2019
5+
* Fixed memory leak in InqMP
6+
* mqmetric - Added ability to set a timezone offset
57
* mqmetric - Added fields from SBSTATUS
68

79
## April 03 2019

buildInDocker.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ cd $GOPATH/src
3030
for pkg in $ORG/$REPO/ibmmq $ORG/$REPO/mqmetric
3131
do
3232
lib=`basename $pkg`
33-
echo "Building $lib"
33+
echo "Building package: $lib"
3434
go install $pkg
3535
done
3636

@@ -41,6 +41,6 @@ srcdir=src/$ORG/$REPO/samples
4141
for samp in $srcdir/*.go
4242
do
4343
exe=`basename $samp .go`
44-
echo "Building $exe"
44+
echo "Building program: $exe"
4545
go build -o bin/$exe $samp
4646
done

ibmmq/mqi.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,6 @@ func (handle *MQMessageHandle) DltMP(godmpo *MQDMPO, name string) error {
11721172
/*
11731173
InqMP is the function to inquire about the value of a message property.
11741174
*/
1175-
11761175
func (handle *MQMessageHandle) InqMP(goimpo *MQIMPO, gopd *MQPD, name string) (string, interface{}, error) {
11771176
var mqrc C.MQLONG
11781177
var mqcc C.MQLONG
@@ -1198,11 +1197,18 @@ func (handle *MQMessageHandle) InqMP(goimpo *MQIMPO, gopd *MQPD, name string) (s
11981197
mqName.VSPtr = (C.MQPTR)(C.malloc(namebufsize))
11991198
mqName.VSBufSize = namebufsize
12001199
}
1200+
// VSPtr is either explicit malloc or comes from CString which does a
1201+
// malloc. Either way, the buffer should be freed at the end.
1202+
defer C.free(unsafe.Pointer(mqName.VSPtr))
12011203

12021204
copyIMPOtoC(&mqimpo, goimpo)
12031205
copyPDtoC(&mqpd, gopd)
12041206

1207+
// Use a local buffer instead of something global so we don't
1208+
// have to worry about multiple threads accessing it.
12051209
propertyPtr = C.PMQVOID(C.malloc(propbufsize))
1210+
defer C.free(unsafe.Pointer(propertyPtr))
1211+
12061212
bufferLength := C.MQLONG(namebufsize)
12071213

12081214
C.MQINQMP(handle.qMgr.hConn,
@@ -1217,10 +1223,6 @@ func (handle *MQMessageHandle) InqMP(goimpo *MQIMPO, gopd *MQPD, name string) (s
12171223
&mqcc,
12181224
&mqrc)
12191225

1220-
if len(name) > 0 {
1221-
C.free(unsafe.Pointer(mqName.VSPtr))
1222-
}
1223-
12241226
mqreturn := MQReturn{MQCC: int32(mqcc),
12251227
MQRC: int32(mqrc),
12261228
verb: "MQINQMP",
@@ -1238,7 +1240,7 @@ func (handle *MQMessageHandle) InqMP(goimpo *MQIMPO, gopd *MQPD, name string) (s
12381240
p := (*C.MQBYTE)(propertyPtr)
12391241
propertyValue = (int8)(*p)
12401242
case C.MQTYPE_INT16:
1241-
p := (*C.MQBYTE)(propertyPtr)
1243+
p := (*C.MQINT16)(propertyPtr)
12421244
propertyValue = (int16)(*p)
12431245
case C.MQTYPE_INT32:
12441246
p := (*C.MQINT32)(propertyPtr)

mqmetric/mqif.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,18 @@ var (
4141
commandLevel int32
4242
resolvedQMgrName string
4343

44+
tzOffsetSecs float64
45+
4446
qmgrConnected = false
4547
queuesOpened = false
4648
subsOpened = false
4749
)
4850

4951
type ConnectionConfig struct {
50-
ClientMode bool
51-
UserId string
52-
Password string
52+
ClientMode bool
53+
UserId string
54+
Password string
55+
TZOffsetSecs float64
5356
}
5457

5558
/*
@@ -64,6 +67,8 @@ func InitConnection(qMgrName string, replyQ string, cc *ConnectionConfig) error
6467
gocno := ibmmq.NewMQCNO()
6568
gocsp := ibmmq.NewMQCSP()
6669

70+
tzOffsetSecs = cc.TZOffsetSecs
71+
6772
// Explicitly force client mode if requested. Otherwise use the "default"
6873
// connection mechanism depending on what is installed or configured.
6974
if cc.ClientMode {

mqmetric/status.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func statusTimeDiff(now time.Time, d string, t string) int64 {
122122
}
123123
parsedT, err = time.ParseInLocation(timeStampLayout, d+" "+t, now.Location())
124124
if err == nil {
125-
diff := now.Sub(parsedT).Seconds()
125+
diff := now.Sub(parsedT).Seconds() + tzOffsetSecs
126126

127127
if diff < 0 { // Cannot have status from the future
128128
// TODO: Perhaps issue a one-time warning as it might indicate timezone offsets
@@ -132,7 +132,7 @@ func statusTimeDiff(now time.Time, d string, t string) int64 {
132132
rc = int64(diff)
133133
}
134134
}
135-
//fmt.Printf("statusTimeDiff d:%s t:%s diff:%d err:%v\n",d,t,rc,err)
135+
//fmt.Printf("statusTimeDiff d:%s t:%s diff:%d tzoffset: %f err:%v\n", d, t, rc, tzOffsetSecs, err)
136136
return rc
137137
}
138138

samples/amqsprop.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ func setProperties(putMsgHandle ibmmq.MQMessageHandle) error {
8686
fmt.Printf("PROP2: %v\n", err)
8787
}
8888

89+
name = "PROP2CINT16"
90+
v2c := 4242
91+
err = putMsgHandle.SetMP(smpo, name, pd, int16(v2c))
92+
if err != nil {
93+
fmt.Printf("PROP2: %v\n", err)
94+
}
95+
8996
name = "PROP3BOOL"
9097
v3 := true
9198
err = putMsgHandle.SetMP(smpo, name, pd, v3)

0 commit comments

Comments
 (0)