Skip to content

Commit 018219e

Browse files
committed
Add GetRenderedEventsTimeout
1 parent 0c6d5ae commit 018219e

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

winlog/winlog.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,28 @@ func DefaultSubscribeConfig() (*SubscribeConfig, error) {
102102
// expensive Windows API calls. Pass in an empty map on the first call. Once
103103
// you've finished using GetRenderedEvents, pass all the contained values to Close.
104104
func GetRenderedEvents(config *SubscribeConfig, publisherCache map[string]windows.Handle, resultSet windows.Handle, maxEvents int, locale uint32) ([]string, error) {
105+
return GetRenderedEventsTimeout(2000 * time.Millisecond, config, publisherCache, resultSet, maxEvents, locale)
106+
}
107+
108+
// GetRenderedEventsTimeout iterates over a subscription or query result set up
109+
// to a configurable maximum and returns the rendered events as a slice of UTF8
110+
// formatted XML strings. A timeout is used to get the first event handles.
111+
// publisherCache is a cache of Handles for publisher metadata to avoid
112+
// expensive Windows API calls. Pass in an empty map on the first call. Once
113+
// you've finished using GetRenderedEvents, pass all the contained values to
114+
// Close.
115+
func GetRenderedEventsTimeout(timeout time.Duration, config *SubscribeConfig, publisherCache map[string]windows.Handle, resultSet windows.Handle, maxEvents int, locale uint32) ([]string, error) {
105116
var events = make([]windows.Handle, maxEvents)
106117
var returned uint32
107118

108119
// Get handles to events from the result set.
109120
err := wevtapi.EvtNext(
110-
resultSet, // Handle to query or subscription result set.
111-
uint32(len(events)), // The number of events to attempt to retrieve.
112-
&events[0], // Pointer to the array of event handles.
113-
2000, // Timeout in milliseconds to wait.
114-
0, // Reserved. Must be zero.
115-
&returned) // The number of handles in the array that are set by the API.
121+
resultSet, // Handle to query or subscription result set.
122+
uint32(len(events)), // The number of events to attempt to retrieve.
123+
&events[0], // Pointer to the array of event handles.
124+
uint32(timeout.Milliseconds()), // Timeout in milliseconds to wait.
125+
0, // Reserved. Must be zero.
126+
&returned) // The number of handles in the array that are set by the API.
116127
if err == windows.ERROR_NO_MORE_ITEMS {
117128
return nil, err
118129
} else if err != nil {

0 commit comments

Comments
 (0)