Hi Yuanzhi,
I wanna know how to find the design document which could tell:
The project is in early stage so there are no detailed design documents. There are few relevant blog posts here: 250bpm.com/blog though.
1. the workflow how the data encapsulate and send to the wire?
nn_send (socket, buffer, buffer_size, flags); see nn_send(3) manual page
2. the communication shceme is the socket synchronous or asynchronous?
It's asynchronous, i.e. when nn_send() exits it means the message was sent, not that it was received by the peer.
3. the transport msg format +---+----+-------+---------- | tag| size | etc ... | payload... +---+----+-------+----------
I guess you are asking about TCP transport:8 byte protocol header followed by messages. Each message starts with 8 byte size in network byte order followed by the payload.
On top of that, there's a messaging-pattern specific protocol (pub/sub, req/rep etc.)
4. the memory management will the lib cause memery fragmentation, how large of payload could the lib send, is there a memory pool, could user custom there own memory management? and so on.
Every program causes some amount of memory fragmentation. You can send anything that fits into memory.There's no nanomsg-specific memory pool. It relies on C runtime/OS to pool the memory.
If you want to use custom memory allocation, just use an alternative implementation of malloc/free/realloc in the way similar to tcmalloc, jemalloc etc. Alternatively you can patch src/utils/alloc.c file and add your memory allocation routines there.
and also i've got an explicit question on REQREP Dose the REQREP support asynchronous msg? I wanna send many request through the same socket at the same time in a message loop, and when replies come back i should deal with it and find the related request. eg. switch (event) { case event_req: send_req(); append_req_to_list(); break; case event_reply: req = get_req_by_reply_from_list(reply); process(req, reply); break; }
You can do that using raw REQ and REP sockets. Use AF_SP_RAW address family when creating the sockets.
Martin