]> sigrok.org Git - libserialport.git/blobdiff - libserialport.h.in
Fix building for Android.
[libserialport.git] / libserialport.h.in
index ff2aaac75bb7b4a01d51f3d86c97bf3646a4e218..41948c1828eee3bab22fdc1e60187233489e88c8 100644 (file)
@@ -756,7 +756,17 @@ enum sp_return sp_set_flowcontrol(struct sp_port *port, enum sp_flowcontrol flow
 */
 
 /**
- * Read bytes from the specified serial port, blocking until available.
+ * Read bytes from the specified serial port, blocking until complete.
+ *
+ * @warning If your program runs on Unix, defines its own signal handlers, and
+ *          needs to abort blocking reads when these are called, then you
+ *          should not use this function. It repeats system calls that return
+ *          with EINTR. To be able to abort a read from a signal handler, you
+ *          should implement your own blocking read using sp_nonblocking_read()
+ *          together with a blocking method that makes sense for your program.
+ *          E.g. you can obtain the file descriptor for an open port using
+ *          sp_get_port_handle() and use this to call select() or pselect(),
+ *          with appropriate arrangements to return if a signal is received.
  *
  * @param port Pointer to port structure.
  * @param buf Buffer in which to store the bytes read.
@@ -793,15 +803,25 @@ enum sp_return sp_nonblocking_read(struct sp_port *port, void *buf, size_t count
  * been transmitted, use the sp_output_waiting() function. To wait until all
  * written bytes have actually been transmitted, use the sp_drain() function.
  *
+ * @warning If your program runs on Unix, defines its own signal handlers, and
+ *          needs to abort blocking writes when these are called, then you
+ *          should not use this function. It repeats system calls that return
+ *          with EINTR. To be able to abort a write from a signal handler, you
+ *          should implement your own blocking write using sp_nonblocking_write()
+ *          together with a blocking method that makes sense for your program.
+ *          E.g. you can obtain the file descriptor for an open port using
+ *          sp_get_port_handle() and use this to call select() or pselect(),
+ *          with appropriate arrangements to return if a signal is received.
+ *
  * @param port Pointer to port structure.
  * @param buf Buffer containing the bytes to write.
  * @param count Requested number of bytes to write.
  * @param timeout Timeout in milliseconds, or zero to wait indefinitely.
  *
- * @return The number of bytes read on success, or a negative error code. If
- *         the number of bytes returned is less than that requested, the
+ * @return The number of bytes written on success, or a negative error code.
+ *         If the number of bytes returned is less than that requested, the
  *         timeout was reached before the requested number of bytes was
- *         sent. If timeout is zero, the function will always return
+ *         written. If timeout is zero, the function will always return
  *         either the requested number of bytes or a negative error code. In
  *         the event of an error there is no way to determine how many bytes
  *         were sent before the error occured.
@@ -827,6 +847,24 @@ enum sp_return sp_blocking_write(struct sp_port *port, const void *buf, size_t c
  */
 enum sp_return sp_nonblocking_write(struct sp_port *port, const void *buf, size_t count);
 
+/**
+ * Gets the number of bytes waiting in the input buffer.
+ *
+ * @param port Pointer to port structure.
+ *
+ * @return Number of bytes waiting on success, a negative error code otherwise.
+ */
+enum sp_return sp_input_waiting(struct sp_port *port);
+
+/**
+ * Gets the number of bytes waiting in the output buffer.
+ *
+ * @param port Pointer to port structure.
+ *
+ * @return Number of bytes waiting on success, a negative error code otherwise.
+ */
+enum sp_return sp_output_waiting(struct sp_port *port);
+
 /**
  * Flush serial port buffers. Data in the selected buffer(s) is discarded.
  *
@@ -840,6 +878,13 @@ enum sp_return sp_flush(struct sp_port *port, enum sp_buffer buffers);
 /**
  * Wait for buffered data to be transmitted.
  *
+ * @warning If your program runs on Unix, defines its own signal handlers, and
+ *          needs to abort draining the output buffer when when these are
+ *          called, then you should not use this function. It repeats system
+ *          calls that return with EINTR. To be able to abort a drain from a
+ *          signal handler, you would need to implement your own blocking
+ *          drain by polling the result of sp_output_waiting().
+ *
  * @param port Pointer to port structure.
  *
  * @return SP_OK upon success, a negative error code otherwise.