aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-07-15 17:11:22 +0200
committerMattias Andrée <maandree@kth.se>2016-07-15 17:11:46 +0200
commitf0fb9bc5f222a157723e57bc4ae4940cc5c7e803 (patch)
treef6c925dcdcf003d284766ac0206d55e800a6e63d /src
parentm + Implement check_error, next_payload, and next_header (diff)
downloadlibcoopgamma-f0fb9bc5f222a157723e57bc4ae4940cc5c7e803.tar.gz
libcoopgamma-f0fb9bc5f222a157723e57bc4ae4940cc5c7e803.tar.bz2
libcoopgamma-f0fb9bc5f222a157723e57bc4ae4940cc5c7e803.tar.xz
Add libcoopgamma_set_nonblocking and prototype for libcoopgamma_synchronise
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--src/libcoopgamma.c48
-rw-r--r--src/libcoopgamma.h32
2 files changed, 78 insertions, 2 deletions
diff --git a/src/libcoopgamma.c b/src/libcoopgamma.c
index d5c25c7..b26c7b8 100644
--- a/src/libcoopgamma.c
+++ b/src/libcoopgamma.c
@@ -20,6 +20,7 @@
#include <sys/socket.h>
#include <sys/wait.h>
#include <errno.h>
+#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
@@ -1275,6 +1276,27 @@ int libcoopgamma_connect(const char* restrict method, const char* restrict site,
/**
+ * By default communication is blocking, this function
+ * can be used to switch between blocking and nonblocking
+ *
+ * @param ctx The state of the library, must be connected
+ * @param nonblocking Nonblocking mode?
+ * @return Zero on success, -1 on error
+ */
+int libcoopgamma_set_nonblocking(libcoopgamma_context_t* restrict ctx, int nonblocking)
+{
+ int flags = fcntl(ctx->fd, F_GETFL);
+ if (nonblocking)
+ flags |= O_NONBLOCK;
+ else
+ flags &= ~O_NONBLOCK;
+ if (fcntl(ctx->fd, F_SETFL, flags) == -1)
+ return -1;
+ return 0;
+}
+
+
+/**
* Send all pending outbound data
*
* If this function or another function that sends a request
@@ -1283,7 +1305,7 @@ int libcoopgamma_connect(const char* restrict method, const char* restrict site,
* be in a properly configured state if a function fails
* with EINTR.
*
- * @param ctx The state of the library, must be initialised
+ * @param ctx The state of the library, must be connected
* @return Zero on success, -1 on error
*/
int libcoopgamma_flush(libcoopgamma_context_t* restrict ctx)
@@ -1313,6 +1335,29 @@ int libcoopgamma_flush(libcoopgamma_context_t* restrict ctx)
/**
+ * Wait for the next message to be received
+ *
+ * @param ctx The state of the library, must be connected
+ * @param pending Information for each pending request
+ * @param n The number of elements in `pending`
+ * @param selected The index of the element in `pending` which corresponds
+ * to the first inbound message, note that this only means
+ * that the message is not for any of the other request,
+ * if the message is corrupt any of the listed requests can
+ * be selected even if it is not for any of the requests.
+ * Functions that parse the message will detect such corruption.
+ * @return Zero on success, -1 on error, -2 if the message is ignored
+ * which happens if corresponding `libcoopgamma_async_context_t`
+ * is not listed
+ */
+int libcoopgamma_synchronise(libcoopgamma_context_t* restrict ctx,
+ libcoopgamma_async_context_t* restrict pending,
+ size_t n, size_t* restrict selected)
+{
+}
+
+
+/**
* Send a message to the server and wait for response
*
* @param resp:char** Output parameter for the response,
@@ -1522,6 +1567,7 @@ static int check_error(libcoopgamma_context_t* restrict ctx, libcoopgamma_async_
}
+
/**
* List all available CRTC:s, send request part
*
diff --git a/src/libcoopgamma.h b/src/libcoopgamma.h
index 3f9c935..cef8fc1 100644
--- a/src/libcoopgamma.h
+++ b/src/libcoopgamma.h
@@ -1208,6 +1208,16 @@ char* libcoopgamma_get_socket_file(const char* restrict, const char* restrict);
int libcoopgamma_connect(const char* restrict, const char* restrict, libcoopgamma_context_t* restrict);
/**
+ * By default communication is blocking, this function
+ * can be used to switch between blocking and nonblocking
+ *
+ * @param ctx The state of the library, must be connected
+ * @param nonblocking Nonblocking mode?
+ * @return Zero on success, -1 on error
+ */
+int libcoopgamma_set_nonblocking(libcoopgamma_context_t* restrict, int);
+
+/**
* Send all pending outbound data
*
* If this function or another function that sends a request
@@ -1216,12 +1226,32 @@ int libcoopgamma_connect(const char* restrict, const char* restrict, libcoopgamm
* be in a properly configured state if a function fails
* with EINTR.
*
- * @param ctx The state of the library, must be initialised
+ * @param ctx The state of the library, must be connected
* @return Zero on success, -1 on error
*/
int libcoopgamma_flush(libcoopgamma_context_t* restrict);
/**
+ * Wait for the next message to be received
+ *
+ * @param ctx The state of the library, must be connected
+ * @param pending Information for each pending request
+ * @param n The number of elements in `pending`
+ * @param selected The index of the element in `pending` which corresponds
+ * to the first inbound message, note that this only means
+ * that the message is not for any of the other request,
+ * if the message is corrupt any of the listed requests can
+ * be selected even if it is not for any of the requests.
+ * Functions that parse the message will detect such corruption.
+ * @return Zero on success, -1 on error, -2 if the message is ignored
+ * which happens if corresponding `libcoopgamma_async_context_t`
+ * is not listed
+ */
+int libcoopgamma_synchronise(libcoopgamma_context_t* restrict, libcoopgamma_async_context_t* restrict,
+ size_t, size_t* restrict);
+
+
+/**
* List all available CRTC:s, send request part
*
* Cannot be used before connecting to the server