# nopoll_conn_get_msg

Definition: | include nopoll.e atom pMsg = nopoll_conn_get_msg(atom conn)
Description: | Get the next message available on the provided connection. The function returns NULL in the case no message is still ready to be returned. This function is design to not block the caller. However, connection socket must be in non-blocking configuration. If you have not configured anything, this is the default. If the function blocks caller then the socket associated to noPollConn is configured to make blocking I/O (maybe because you configured like this or the socket was passed to another library that did such configuration or maybe because you are using nopoll_conn_new_with_socket). conn: The connection where the read operation will take place. Returns: A reference to a noPollMsg object or NULL if there is nothing available. In case the function returns NULL, check connection status with nopoll_conn_is_ok(). The returned value should be considered opaque and contents from it retrieved using routines such as nopoll_msg_get_payload() and nopoll_msg_opcode().
Example: | Copy
    --DEV not tested!
    include nopoll.e

    function on_message(atom /*ctx*/, conn, pMsg, /*user_data*/)
        printf(1,"%s\nThe size of message is %d bytes\n",
                 {nopoll_msg_get_payload(pMsg),
                  nopoll_msg_get_payload_size(pMsg)})
        ?nopoll_conn_send_text(conn, "Hello World")
        return 0 -- (rqd for call_back, otherwise ignored)
    end function
    constant on_message_cb = call_back(routine_id("on_message"))

    atom ctx = nopoll_ctx_new()
    if ctx=NULL then ?9/0 end if

    --DEV?? conn = ??
    -- create a listener to receive connections on port 1234
    atom listener = nopoll_listener_new(ctx, "0.0.0.0", "9999");
    if not nopoll_conn_is_ok(listener) then ?9/0 end if

    -- now set a handler that will be called when a message (fragment or not) is received
    nopoll_conn_set_on_msg(conn, on_message_cb, NULL)

    -- now call to wait for the loop to notify events
    integer error_code = nopoll_loop_wait(ctx, 0)

    nopoll_ctx_unref(ctx)
See Also: | nopoll_conn_is_ok, nopoll_msg_get_payload, nopoll_msg_get_payload_size, nopoll_conn_is_ready, nopoll_conn_read