# nopoll_conn_read

Definition: | include nopoll.e {integer n, string s} = nopoll_conn_read(atom conn, integer bytes, bool block, integer timeout)
Description: | Read the specified number of bytes from the provided connection. Optionally, the function allows blocking the caller until the amount of bytes requested are satisfied. Also, the function allows to timeout the operation after provided amount of time. conn: The connection where the read operation will take place. bytes: Number of bytes to be read from the connection. block: If true, the caller will be blocked until the amount of bytes requested are satisfied or until the timeout is reached (if enabled). If false, the function won’t block and will return all bytes available at this moment. timeout: (in milliseconds, 1sec = 1000ms) If given a value higher than 0, a timeout will be enabled to complete the operation. If the timeout is reached, the function will return the bytes read so far. Please note that the function has a precision of 10ms. Returns: Number of bytes read, along with a string containing the bytes actually read, or -1 and "" if it fails. The function returns -1 when no content is available to be read and you pass block == false More calls to nopoll_conn_read might be needed. Because nopoll_conn_read() calls nopoll_conn_get_msg() to get content to satisfy the read requested, it might happen that the actual amount of bytes requested by this function (nopoll_conn_read) is smaller than the number of bytes that can be satisfied (because nopoll_conn_get_msg reported a noPollMsg with bigger content). In such case, these bytes will be reported on next call to nopoll_conn_read. However, it might also happen that the socket is being watched (by select(), poll(), epoll(), similar mechanism) and because all bytes have been read and are retained in a noPollMsg inside the provided noPollConn) this might cause a block until a forced nopoll_conn_read happens again (because the socket does not report any content to be read and nopoll_conn_read is not called). In such scenarios, if you want to avoid such lockings, please use nopoll_conn_read_pending to do more calls to nopoll_conn_read
See Also: | nopoll_conn_read_pending, nopoll_conn_get_msg, nopoll_conn_is_ok, nopoll_msg_get_payload, nopoll_msg_get_payload_size