digitalmars.D.learn - Integrate vibe.d into Windows Service
- Andre Pany (33/33) Nov 21 2018 Hi,
- Kagamin (2/2) Nov 21 2018 Start vibe in another thread and return from ServiceMain, see
- Andre Pany (4/6) Nov 21 2018 Thanks a lot. I will try.
- Andre Pany (10/12) Nov 23 2018 I tried to wrap WaitForSingleObject into a Fiber by using command
- Kagamin (4/4) Nov 23 2018 You don't need to initialize runtime because it's initialized by
- Andre Pany (6/10) Nov 23 2018 Thank you, I wasn't aware of this. For references, I found this
- Andre Pany (3/13) Nov 23 2018 Post explaining thread_attachThis
- Daniel Kozak (4/8) Nov 27 2018 Today I needed this too, and after some searching I came across
Hi, I translated the CPP example of a windows service to D. https://docs.microsoft.com/en-us/windows/desktop/Services/svc-cpp I wonder how can I integrate a vibe.d http server here: __gshared HANDLE ghSvcStopEvent = NULL; VOID SvcInit(DWORD dwArgc, LPTSTR* lpszArgv) { ghSvcStopEvent = CreateEvent(NULL, // default security attributes TRUE, // manual reset event FALSE, // not signaled NULL); // no name if (ghSvcStopEvent == NULL) { ReportSvcStatus(SERVICE_STOPPED, NO_ERROR, 0); return; } ReportSvcStatus(SERVICE_RUNNING, NO_ERROR, 0); // TO_DO: Perform work until service stops. while (1) { WaitForSingleObject(ghSvcStopEvent, INFINITE); ReportSvcStatus(SERVICE_STOPPED, NO_ERROR, 0); return; } } WaitForSingleObject will wait forever until ghSvcStopEvent will be filled (by extern (Windows) VOID SvcCtrlHandler(DWORD dwCtrl) nothrow). Do you have any proposal how to integrate vibe.d here? Kind regards André
Nov 21 2018
Start vibe in another thread and return from ServiceMain, see https://docs.microsoft.com/en-us/windows/desktop/Services/service- ervicemain-function also ideally you should report running state only after vibe initialized, opened sockets and started listening, before that it's not really running.
Nov 21 2018
On Wednesday, 21 November 2018 at 15:05:31 UTC, Kagamin wrote:Start vibe in another thread and return from ServiceMain, see https://docs.microsoft.com/en-us/windows/desktop/Services/service- ervicemain-function also ideally you should report running state only after vibe initialized, opened sockets and started listening, before that it's not really running.Thanks a lot. I will try. Kind regards Andre
Nov 21 2018
On Wednesday, 21 November 2018 at 15:05:31 UTC, Kagamin wrote:Start vibe in another thread and return from ServiceMain, see https://docs.microsoft.com/en-us/windows/desktop/Services/service- ervicemain-function also ideally you should report running state only after vibe initialized, opened sockets and started listening, before that it's not really running.I tried to wrap WaitForSingleObject into a Fiber by using command runTask. In theory it should work fine but the service (app) just crash without any information on an empty runTask function. Also calling listenHTTP crashes the service. Here I am able to catch the Error "eventcore.core static constructor didn't run!?". I created a github issue with complete source code here https://github.com/vibe-d/vibe-core/issues/105 Kind regards Andre
Nov 23 2018
You don't need to initialize runtime because it's initialized by standard D startup code, but you need to attach threads that are not created by D or static constructors won't be run and only C-level code would work there.
Nov 23 2018
On Friday, 23 November 2018 at 21:27:26 UTC, Kagamin wrote:You don't need to initialize runtime because it's initialized by standard D startup code, but you need to attach threads that are not created by D or static constructors won't be run and only C-level code would work there.Thank you, I wasn't aware of this. For references, I found this post which explains thread_attachThis. I assume you meant this function. Kind regards Andre
Nov 23 2018
On Friday, 23 November 2018 at 21:35:57 UTC, Andre Pany wrote:On Friday, 23 November 2018 at 21:27:26 UTC, Kagamin wrote:Post explaining thread_attachThis https://forum.dlang.org/thread/ounui4$171a$1 digitalmars.comYou don't need to initialize runtime because it's initialized by standard D startup code, but you need to attach threads that are not created by D or static constructors won't be run and only C-level code would work there.Thank you, I wasn't aware of this. For references, I found this post which explains thread_attachThis. I assume you meant this function. Kind regards Andre
Nov 23 2018
On Wednesday, 21 November 2018 at 09:59:19 UTC, Andre Pany wrote:Hi, I translated the CPP example of a windows service to D. https://docs.microsoft.com/en-us/windows/desktop/Services/svc-cpp [...]Today I needed this too, and after some searching I came across this package which works ok for me with vibed: https://code.dlang.org/packages/daemonize
Nov 27 2018