nats-io / nats.c Goto Github PK
View Code? Open in Web Editor NEWA C client for NATS
License: Apache License 2.0
A C client for NATS
License: Apache License 2.0
/tmp/ccPXXpFE.s: Assembler messages:
/tmp/ccPXXpFE.s:204: Error: bad instruction `rep'
make[2]: *** [src/CMakeFiles/nats.dir/unix/mutex.c.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [src/CMakeFiles/nats.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
and
[ 88%] Building C object src/CMakeFiles/nats_static.dir/unix/thread.c.o
/tmp/ccvzGzHd.s: Assembler messages:
/tmp/ccvzGzHd.s:174: Error: bad instruction `rep'
make[2]: *** [src/CMakeFiles/nats_static.dir/unix/mutex.c.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [src/CMakeFiles/nats_static.dir/all] Error 2
make: *** [all] Error 2
Hi, there
I am a fan of gnatsd and its clients. I am heavy user of cnat client library for high-throughput project.
Here is a tip for developer using mingw64, which I found it.
If you are a user, using mingw64/32 in msys2 environment, you should add the followings in CMakeLists.txt of the root folder.
My environments:
msys2 (latest one: 20161025 for x86_64, and getting the latest packages with msys2, pacman, dev tools)
mingw64 (gcc / g++ 6.3)
Around line number 75~77, you could find below
elseif(WIN32)
set(NATS_OS "_WIN32")
set(NATS_PLATFORM_INCLUDE "win")
in the above section, the followings are added.
elseif(WIN32)
message("WIN32")
set(NATS_EXTRA_LIB "Ws2_32")
set(NATS_OS "_WIN32")
set(NATS_PLATFORM_INCLUDE "win")
Then, run cmake with -G "MSYS Makefiles" --> mingw32-make.exe
Finally it works
// Dear Team,
if possible, could you please add the above in the CMakeLists.txt ?
Many thanks!
Two of the installed header files include "nats.h", rather than "nats/nats.h":
$ pwd
/usr/local/include/nats
$ grep -ir "nats\.h" .
./adapters/libevent.h:#include "nats.h"
./adapters/libuv.h:#include "nats.h"
This causes warnings (from the pragma in "nats.h"):
$ clang libuv-sub.c -luv -lnats
In file included from libuv-sub.c:5:
In file included from ./examples.h:7:
/usr/local/include/nats.h:7:2: warning: "`#include <nats.h>` is deprecated. Please use `#include <nats/nats.h>`"
[-W#warnings]
#warning "`#include <nats.h>` is deprecated. Please use `#include <nats/nats.h>`"
^
1 warning generated.
Server feature added in this PR: nats-io/nats-server#698
Are publish's in a separate thread or will they block the thread the connection is created in?
Thanks! - Great work no the library btw
I have test the following code.
for(i=1;i<101;i++) { for(j=1;j<1001;j++) { natsConnection_Publish(nc,subject,bf,bfsz); // bfsz=136 } }
I use two nodes. One node A publish 10w messages, cost about 330ms, and take 8.9 cpu. The other node B publish 10w messages, cost about 1363ms, and take 3.3 cpu.
I want to improve node B performance, and it can publish 10w messages within 1000ms. I don't known the performance bottleneck.
Dear Nats Team,
Have any plan supporting nats stream with c library?
Best regards,
I am facing some strange behavior with natsConnection_SubscribeSync. It does not work with dynamically allocated string. Any explanation? Anything to do with heap vs stack allocation?
const chat *s="chatManager";
natsConnection_QueueSubscribeSync(&sub, conn, s, workerName); -- works
natsConnection_QueueSubscribeSync(&sub, conn, "chatManager", workerName); -- works
char topic[128];
strncpy(topic, "chatManager", 128)
natsConnection_QueueSubscribeSync(&sub, conn, topic, workerName); -- does not work
chat topic;
topic = (char) malloc(sizeof(char) * 128);
strncpy(topic, "chatManager", 128);
natsConnection_QueueSubscribeSync(&sub, conn, topic, workerName); -- does not work
i want to use nats at ios platform,how to support?
The README.md says:
natsOptions_Destroy(nc);
Which should be:
natsOptions_Destroy(opts);
the head file adapter/libevent.h can't include more times, else LD failed.
Per requirements of the move to CNCF
See: nats-io/nats.go#118
The pub/sub api seems support string only.
As discussed on slack, VLD reports several small leaks when linking cnats statically. This is because thread-local and global allocations are actually released during cnats DllMain()
function (or it's unix equivalent). However, DllMain()
will not be called obviously when static linking (and may also introduce symbol conflicts when creating a DLL which statically links to cnats).
While the allocations are actually uncritical, since they are small and not growing, they may make hunting for actual leaks harder (in the end, everyone wants a clean memory report after debugging)
I've created a fix for that already but one small thing is still left to discuss.
First of all, I've created a NATS_STATIC
symbol and avoid creating of DllMain()
when defined. Then, I've created a NATS_EXAMPLES_STATIC_LINKING
option to cmake for testing.
For the actual fix, I've created and implemented two new functions:
/** \brief Per-Thread cleanup function for static library
*
* When linking to the static library, this should be called at the end of
* each thread where NATS objects have been created or used.
*
* \note This has no effect when called from the shared library.
* nats_Close() implicitly calls that.
*/
NATS_EXTERN void
nats_ReleaseThreadMemory(void);
/** \brief Global cleanup function for static library
*
* When linking to the static library, this should be called at the end of
* the application in order to perform library cleanup.
* IMPORTANT The library may not be re-used again after calling this.
*
* \note This has no effect when called from the shared library.
*/
NATS_EXTERN void
nats_ReleaseStaticLibrary(void);
nats_ReleaseThreadMemory()
is already called by nats_Close()
, so for many actual implementations it shouldn't be necessary to call that.
In my first try, I also called nats_ReleaseStaticLibrary()
from nats_Close()
. However this may break existing code: Until now, it was possible to "reuse" the library after nats_Close()
has been called. However, I assume the intention of calling nats_Close()
is to perform some final cleanup. If that is the case, we may also call nats_ReleaseStaticLibraray()
from nats_Close()
, making the whole static library cleanup automatic (except for multi-threaded applications where nats_ReleaseThreadMemory()
is still required to be called for obvious reasons).
Background: nats_ReleaseStaticLibrary()
performs the cleanup which a shared lib does during DllMain(DLL_PROCESS_DETACH)
, which means deleting the mutex. However, the mutex cannot be reinitialized cause for doing so gInitOnce
must be reset (which cannot be done in clean code; we could of course hack this)
I've got my code ready for creating a PR but will wait for feedback on this issue before filing.
nats_JSONParse function doesn't work if Windows locale settings for decimal symbol is comma.
_jsonGetNum takes number ("port":4222,) with comma, but should without.
strtold function gets locale settings. Probably should be used _strtold_l function with constant english locale settings.
My JSON file:
{"server_id":"Ehv4Cv12sdLR51ETe8EYYV","version":"1.0.4","go":"go1.8.3","host":"0.0.0.0","port":4222,"auth_required":false,"ssl_required":false,"tls_required":false,"tls_verify":false,"max_payload":1048576}
Hi,
Not an issue exactly.
Do you have an example using linux pthreads alone? I want to avoid using libevent and libuv.
I have another application which needs to send/recv NATS messages. I need to create 2 threads, one send thread and one receive thread which will do only NATS send and recv translation for the application in question. Do you have any examples?
Regards,
Umesh
Currently there is no way to build just the library, without also building the examples.
Ref: https://github.com/nats-io/cnats/blob/v1.5.0/examples/CMakeLists.txt#L45
Hi
I'm a beginner in C. I'm familiar with nats from go, but am hoping someone can answer the following question for me...
The question:
If I have a single nats connection called 'nc', and I have multiple publishers and multiple subscribers all in the same thread... do I need to protect anything with mutex locking?
In case it's relevant:
Thanks a lot for any help
Any plans to add C++ support?
#ifdef __cplusplus
extern "C" {
#endif
// Nats C code
#ifdef __cplusplus
}
#endif
The nats-io/go-nats
TLS connect implementation skips verification by default but I'm getting an SSL error for self signed certificates by default with a minimal cnats TLS client on this line: https://github.com/nats-io/cnats/blob/master/src/conn.c#L580
Should the client rc
checks there be modified to match the Go implementation and ignore self signed certs?
Hello, I noticed that if I don't call natsConnection_ConnectTo after including #include"nats.h" cnats crashes on windows.
Debugger report:
Unhandled exception at 0x779B9F83 (ntdll.dll) in launcher.exe: 0xC0000005: Access violation writing location 0x00000004.
If there is a handler for this exception, the program may be safely continued.
natsMutex_Lock(natsMutex *m)
{
// If gLockSpinCount > 0, the mutex has been created as as spin lock,
// so we don't have to do anything special here.
EnterCriticalSection(m); //< ------ crash here with access violation
}
Where m is NULL.
I will try to reproduce the issue later in the week to be sure that it is not actually me being a bad programmer. Just wanted to know if you noticed anything like that.
Since nats_Open
uses InitOnce, the following code doesn't work.
nats_Open(-1);
...
nats_Close();
...
nats_Open(-1); // fail!
In my project, it's almost impossible to call nats_Close
at the end of the program (for exampe, atexit
), but I don't want to leak memory (We have leak check in our CI). My solution was calling nats_Close
at the destructor of my NatsClient class, but with that solution, I can't create the second NatsClient object after the first one's destruction.
Is there any way to do the open-close-open-close sequence appropriately?
Hello,
If I understand well, using cnats:
natsOptions_SetEventLoop
,I think I would be good to present the threading model of the library more clearly in the Github README, because the information is currently scattered across it, and could be presented in a somewhat more helpful manner for complex systems design.
For example, I have first thought that the "reading thread" and "dispatching thread" were the same thing and that cnats would allow me to fully control the threading model of my program through natsOptions_SetEventLoop
(I thought that the user could specify a fixed number of threads containing each an event loop where I could submit, for instance, both NATS-originated and timer-originated processing tasks, which would imply that I could manage the threads and the event loops myself - this model is not possible with cnats as far as I understand).
Anyway, the API design is generally very good and it seems to be fast, so thanks for maintaining this great library.
I'm using cnats in an application which requires asynchronous responses to a request. I know that natsConnection_Request
exists but it blocks until the response has been returned from the broker.
I reasoned that asynchronicity could be achieved using natsConnection_Subscribe
to a temporary subject and calling natsSubscription_AutoUnsubscribe(sub, 1)
to make sure that it's unsubscribed right after. However, the problem is that the subscription also needs to be destroyed and the memory freed. How could this be done without modifying cnats (if at all)?
Trying to send a message using this function produces a parsing error on the server.
Examples (in /examples) are currently written in a sort of tech-demo-style (aka look-how-cool-this-is-style). I would rather see examples with a pedagogical focus ("see how easy it is to get started"-style). Currently, when you read the examples, you zoom back and forth between examples.h
and the source file, and you try to simplify the example to it's bare bones. Not super helpful.
A couple of things I'd like to see:
subscriber.c
into asyncsubscriber.c
and syncsubscriber.c
. People like specific examples. General logic is not "example"-material.printStats
. Create a stats.c
where you can flash with your awesome statistics instead! Actually, you should create a benchmark/
-folder and put stats-stuff in there, that way you can be flashy and pedagogical at the same time!If tech-demo-style is your thing, then don't let me get in the way, but I think that programmers getting to know your library (people like me) would be grateful to have simple bare-bones look-how-easy-this-is no-frills examples to start off with. An example with 10 lines of code would scream "this is easy" - which is something everyone enjoys.
Hello I was wondering if you tried compiling cnats for android.
is it possible to use cnats with boost.asio?
Some race conditions could cause a crash after the library reconnects and is trying to flush the pending buffer. This would cause valgrind to report invalid read/writes:
==3410== Invalid read of size 4
==3410== at 0x567FF19: pthread_mutex_lock (pthread_mutex_lock.c:84)
==3410== by 0x4441A1: natsMutex_Lock (in /home/travis/build/nats-io/cnats/build/test/testsuite)
==3410== by 0x43727B: natsConnection_FlushTimeout (in /home/travis/build/nats-io/cnats/build/test/testsuite)
==3410== by 0x439196: _doReconnect (in /home/travis/build/nats-io/cnats/build/test/testsuite)
==3410== by 0x444599: _threadStart (in /home/travis/build/nats-io/cnats/build/test/testsuite)
==3410== by 0x567DE99: start_thread (pthread_create.c:308)
==3410== Address 0x6075218 is 8 bytes inside a block of size 40 free'd
==3410== at 0x4C2A82E: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3410== by 0x4355A8: _freeConn (in /home/travis/build/nats-io/cnats/build/test/testsuite)
==3410== by 0x413324: test_ReconnectServerStats (in /home/travis/build/nats-io/cnats/build/test/testsuite)
==3410== by 0x407101: main (in /home/travis/build/nats-io/cnats/build/test/testsuite)
==3410==
==3410== Invalid write of size 4
==3410== at 0x567FF24: pthread_mutex_lock (pthread_mutex_lock.c:85)
==3410== by 0x4441A1: natsMutex_Lock (in /home/travis/build/nats-io/cnats/build/test/testsuite)
==3410== by 0x43727B: natsConnection_FlushTimeout (in /home/travis/build/nats-io/cnats/build/test/testsuite)
==3410== by 0x439196: _doReconnect (in /home/travis/build/nats-io/cnats/build/test/testsuite)
==3410== by 0x444599: _threadStart (in /home/travis/build/nats-io/cnats/build/test/testsuite)
==3410== by 0x567DE99: start_thread (pthread_create.c:308)
==3410== Address 0x6075214 is 4 bytes inside a block of size 40 free'd
==3410== at 0x4C2A82E: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3410== by 0x4355A8: _freeConn (in /home/travis/build/nats-io/cnats/build/test/testsuite)
==3410== by 0x413324: test_ReconnectServerStats (in /home/travis/build/nats-io/cnats/build/test/testsuite)
==3410== by 0x407101: main (in /home/travis/build/nats-io/cnats/build/test/testsuite)
nats.h defines a static const char* (NATS_DEFAULT_URL). This has the effect of causing compiler warnings unless the variable is used. Either a #define or an extern declaration with the value set in some .c file would be a reasonable fix for this.
I'd put in a PR but wasn't sure what your preferences were.
Hello I was trying to compile CNATS for a specific ubuntu 14 arm64 box and when I get to the make install part I keep getting this error:
[ 1%] Building C object src/CMakeFiles/nats.dir/unix/mutex.c.o
/tmp/ccjNLaiT.s: Assembler messages:
/tmp/ccjNLaiT.s:176: Error: unknown mnemonic rep' --
rep'
src/CMakeFiles/nats.dir/build.make:542: recipe for target 'src/CMakeFiles/nats.dir/unix/mutex.c.o' failed
make[2]: *** [src/CMakeFiles/nats.dir/unix/mutex.c.o] Error 1
CMakeFiles/Makefile2:983: recipe for target 'src/CMakeFiles/nats.dir/all' failed
make[1]: *** [src/CMakeFiles/nats.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
I wonder if any of you has any Idea how to fix this. I was thinking of making my own simple makefile but I need to figure out how to handle forward declarations.
I also tried to compile it in another consumer arm 64 box and it works.
Dear,
My system is : CentOS 6.7 x86_64
uname -r : 2.6.32-573.7.1.el6.x86_64
When build the library/examples/testsuite, I get:
[ 79%] Built target nats_static
Scanning dependencies of target nats-publisher
[ 81%] Building C object examples/CMakeFiles/nats-publisher.dir/publisher.c.o
[ 82%] Linking C executable nats-publisher
../src/libnats.so: undefined reference to `clock_gettime'
collect2: ld returned 1 exit status
make[2]: *** [examples/nats-publisher] Error 1
make[1]: *** [examples/CMakeFiles/nats-publisher.dir/all] Error 2
make: *** [all] Error 2
I not experience in cmake, but manually in link.txt files, I add at end :
-Wl,--no-as-needed -lrt
My build problem solved
../examples/CMakeFiles/nats-publisher.dir/link.txt
../examples/CMakeFiles/nats-queuegroup.dir/link.txt
../examples/CMakeFiles/nats-replier.dir/link.txt
../examples/CMakeFiles/nats-requestor.dir/link.txt
../test/CMakeFiles/testsuite.dir/link.txt
JM
Can we use cnats client on windows platform? And which complier is supported?
Hello,
First of all, thank you so much for cnats. The library's API looks very extensive and the design is clean. README and examples are pretty good too. Building it in Visual Studio worked like a charm.
Still the online help is limited to very brief descriptions of the API without any summary page that would describe how the library actually works under the hood. I'm developing a (hopefully robust) C++/Qt wrapper over cnats, and seeing how much work has been invested in thread safety, buffering, performance, thread pools, reconnections etc in cnats, I want to use this to full potential instead of restricting myself to minimal cnats API and re-doing all these things myself using Qt.
This wrapper will be used in a large and multi-threaded application, so this is what I'm wondering about:
Is the library thread-safe? can I create a connection/subscription/statistics in one thread, use it in another and destroy in a third thread? I see you already have an answer here #50 but it would be nice to have documented.
How do threads and subscription buffers work? You partially answer this here #59 but a more complete description would be nice.
2.1. On the publisher's side, it is unclear what is the purpose of natsConnection_Flush. All examples always use it. Should I use it too? Should I flush after every message? If I just want to flush the I/O buffer, why do I need to wait till gnatsd replies with a pong? or simply use natsOptions_SetSendAsap? If I don't use it, how much time my messages will wait before being sent?
Finally, what if I publish messages too fast for cnats to send them over network - will the buffer grow indefinitely? Can I query for a number of outgoing messages in the buffer?
2.2. On the (async) subscriber's side, is my understanding correct that the library starts a new thread to read data from a socket as fast as possible, store it in a buffer and then pass to a callback's thread? So, the "Slow consumers" scenario as described here http://nats.io/documentation/server/gnatsd-prune/ is not possible with cnats, but rather replaced with NATS_SLOW_CONSUMER, correct?
If you have natsOptions_UseOldRequestStyle, what is the new request style then? I can see how it works over network with gnatsd -DV though. Does it mean that if many services reply to a request, gnatsd will send all replies to the requestor, and then cnats will deliver the first reply and discard the rest? and with the old style this work is performed by gnatsd?
Do I need to use nats_ReleaseThreadMemory only when I integrate cnats with an event loop, or when doing any kind of publishing or subscribing in a background thread?
What does this comment means in one of your examples?
// For maximum performance, set no limit on the number of pending messages.
s = natsSubscription_SetPendingLimits(sub, -1, -1);
How do the limits affect performance?
I am running the "nats-subscriber" example with -count 30 and "nats-publisher" with -count 30 (both on the same Windows 7 host, no TLS, MSVC x64). After running the publisher, this is what I get in console output of the subscriber:
In Msgs: 30 - In Bytes: 150 - Delivered: -3689348814741910324 - Pending: 0 - Dropped: 0 - Reconnected: 0
I think, the number of delivered messages got wrong somehow?
Some summary about how reconnection works, also in a cluster environment, would be useful too IMHO. I think I can derive this information from careful reading of all related API functions, but still I can miss something.
Thanks in advance.
Hi NATS team !
As a big fan of NATS, I found a small typo in the main page.
// Our object definition
typdedef struct __Errors
{
int count;
} Errors;
In the above, typededef would be typedef.
Could you please update on it ?
Thank you for your continuous effort
Hello Im working on an IoT project and NATS seems a perfect fit but streaming is a must so we dont loose any message, any plans for c streaming client lib? I think would be great for IoT projects
In Msgs: 30 - In Bytes: 150 - Delivered: -3689348814741910324 - Pending: 0 - Dropped: 0 - Reconnected: 0
This is from go-nats (https://github.com/nats-io/go-nats/issues/294)
Every request forms a new INBOX subscription for each request and then tears them down. Since NATS has to flood the interest graph to clusters and possible future bridged clusters, this should be redesigned to reuse a single subscription but still be semantically be the same from a client perspective. One word of caution is that we use the circuit breaker pattern such that the server auto-unsubscribes after N responses (usually 1), so if you are requesting from a large set of normal subscribers, the client may be getting a higher number of responses that will be ignored. However I feel the normal case should be a request is always sent to a queue group, which does not need the circuit breaker assist.
Example trace from a single request / response today.
[TRC] ::1:50431 - cid:2 - ->> [SUB _INBOX.Gmw3KasVkAqYFpskoKCV79 1]
[TRC] ::1:50431 - cid:2 - ->> [UNSUB 1 1]
[TRC] ::1:50431 - cid:2 - ->> [PUB foo _INBOX.Gmw3KasVkAqYFpskoKCV79 4]
[TRC] ::1:50431 - cid:2 - ->> MSG_PAYLOAD: [help]
[TRC] ::1:50426 - cid:1 - <<- [MSG foo 1 _INBOX.Gmw3KasVkAqYFpskoKCV79 4]
[TRC] ::1:50426 - cid:1 - ->> [PUB _INBOX.Gmw3KasVkAqYFpskoKCV79 5]
[TRC] ::1:50426 - cid:1 - ->> MSG_PAYLOAD: [hello]
[TRC] ::1:50431 - cid:2 - <<- [MSG _INBOX.Gmw3KasVkAqYFpskoKCV79 1 5]
[TRC] ::1:50431 - cid:2 - <-> [DELSUB 1]
This desired behavior is discussed in https://github.com/nats-io/go-nats/issues/310. Is it supported in cnats somehow?
Currently, cnats installs the cnats-specific header files status.h
and version.h
to $PREFIX/include/
. While the other header might make sense at /usr/local/include/nats.h
and /usr/include/nats.h
, /usr/local/include/status.h
or /usr/include/status.h
do not. Same goes for version.h
.
TL;DR: They would make sense if they were installed as something like /usr/include/nats-status.h
or /usr/include/nats/status.h
A suggestion : I used make (not familiar with cmake) to build a project. The install process installs the lib to /usr/local/lib - it might be nice for the install to create a symbolic link to this file in /usr/lib (especially if LD_LIBRARY_PATH is not set).
Ubuntu 18.04
Hello, I was doing some tests with cnats on windows (vs2015) and I noticed that when a NATS server is not running, often the call to natsConnection_ConnectTo makes my program crash. My code is something as simple as:
natsConnection *_pnc = NULL;
int rc = 0;
if ((rc = natsConnection_ConnectTo(&_pnc, NATS_DEFAULT_URL)) != 0) {
printf("Connection failed...\n\n");
natsConnection_Destroy(_pnc);
}
with:
Unhandled exception at 0x77049F83 (ntdll.dll) in launcher.exe: 0xC0000005: Access violation writing location 0x00000004.
In particular, the problem happens here:
natsMutex_Lock(natsMutex *m)
{
// If gLockSpinCount > 0, the mutex has been created as as spin lock,
// so we don't have to do anything special here.
EnterCriticalSection(m);
}
(m is NULL)
Called by
_cleanupThreadLocals(void)
{
void *tl = NULL;
tl = natsThreadLocal_Get(gLib.errTLKey);
if (tl != NULL)
_destroyErrTL(tl);
tl = NULL;
natsMutex_Lock(gLib.lock);
....
when build with visual studio 2015, snprintf can't define as macro
patch diff
src/include/n-win.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/include/n-win.h b/src/include/n-win.h
index 9d46918..ab231b2 100644
--- a/src/include/n-win.h
+++ b/src/include/n-win.h
@@ -42,7 +42,10 @@ typedef int natsRecvLen;
#define NATS_SOCK_GET_ERROR WSAGetLastError()
// Windows doesn't have those..
-#define snprintf _snprintf
+#if _MSC_VER < 1900
+#define snprintf _snprintf
+#endif
+
#define strcasecmp _stricmp
int
Dear NATS team
In the adapters/libuv.h, below changes would be needed since the adapter cannot attach the event loop in the window. Also my windows environment consists of Mingw64 and libuv 1.14.0.
error:
Error: 1 - Error - (conn.c:1484): Error attaching to the event loop: 1 - Error
Stack: (library version: 1.7.0)
01 - _processConnInit
02 - _connect
03 - natsConnection_Connect
workaround:
#if defined(_WIN32) || defined(_WIN64) || defined(__MINGW32__) || defined(__MINGW64__)
if ((s == NATS_OK)
&& (uv_poll_init_socket(nle->loop, nle->handle, nle->socket) != 0))
#else
if ((s == NATS_OK)
&& (uv_poll_init(nle->loop, nle->handle, nle->socket) != 0))
#endif
I assume this issue is caused by the type of Windows socket might be not as same as the one of the linux or unix.
After investigating this, if yes, could you please apply the above changes as well ?
Thank you for your continuous development
The following code often fails in my Linux (Ubuntu 16.04) environment.
#include <nats.h>
#include <thread>
#include <iostream>
static void sub() {
natsStatus s = nats_Open(-1);
if (s != NATS_OK) {
std::cout << "Open failed: " << natsStatus_GetText(s) << std::endl;
} else {
nats_Close();
}
}
int main() {
std::thread th(sub);
sub();
th.join();
return 0;
}
Error message will be:
% g++ -std=c++11 -Wall -I ../src foo.cpp -Lsrc -lnats_static -lpthread && ./a.out
Open failed: Initialization Failed
Guarding both nats_Open
and nats_Close
with mutex lock fixes the issue.
Is that expected? If mutex lock is necessary by spec, the document should be updated so.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.