lib: do initialize Windows Sockets on startup
Without calling WSAStartup(), Windows does not allow us to create
sockets at all. We forgot to call it in the embedding interface.
Note that the initialization code is borrowed from fluent-bit.c
#include <mcheck.h>
#endif
+#ifdef FLB_SYSTEM_WINDOWS
+static inline int flb_socket_init_win32(void)
+{
+ WSADATA wsaData;
+ int err;
+
+ err = WSAStartup(MAKEWORD(2, 2), &wsaData);
+ if (err != 0) {
+ fprintf(stderr, "WSAStartup failed with error: %d\n", err);
+ return err;
+ }
+ return 0;
+}
+#endif
+
static inline struct flb_input_instance *in_instance_get(flb_ctx_t *ctx,
int ffd)
{
@@ -95,6 +110,13 @@ flb_ctx_t *flb_create()
mtrace();
#endif
+#ifdef FLB_SYSTEM_WINDOWS
+ /* Ensure we initialized Windows Sockets */
+ if (flb_socket_init_win32()) {
+ return NULL;
+ }
+#endif
+
ctx = flb_calloc(1, sizeof(flb_ctx_t));
if (!ctx) {
perror("malloc");
