Skip to content

Commit

Permalink
daemon: Enable to handle user defined control codes
Browse files Browse the repository at this point in the history
128 to 255 for windows service's control codes are user-defined:

  https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-controlservice

but win32-service doesn't handle these codes.

This commit adds a handler for them.
  • Loading branch information
ashie committed Nov 20, 2020
1 parent bfeaedf commit b4dc5a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/daemon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ Daemon#service_paramchange
Called if the service receives a SERVICE_CONTROL_PARAMCHANGE signal.
This notifies a service that its startup parameters have changed.

Daemon#service_user_defined_control(code)
Called if the service receives a user-defined control code (128 to 255).

= Constants

=== Service state constants
Expand Down
8 changes: 8 additions & 0 deletions lib/win32/daemon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,14 @@ def mainloop
when SERVICE_CONTROL_NETBINDDISABLE
service_netbinddisable() if respond_to?('service_netbinddisable')
end

# handle user defined control codes
if @@waiting_control_code >= 128 && @@waiting_control_code <= 255
if respond_to?('service_user_defined_control')
service_user_defined_control(@@waiting_control_code)
end
end

@@waiting_control_code = IDLE_CONTROL_CODE
end

Expand Down

0 comments on commit b4dc5a1

Please sign in to comment.