ipc2: started working on event-based ipc handling.

This commit is contained in:
Martin Preuss
2025-01-09 01:42:19 +01:00
parent b2193afa46
commit acbe4505b9
11 changed files with 963 additions and 5 deletions

View File

@@ -13,6 +13,11 @@
#include "./fdobject_p.h"
#include <gwenhywfar/inherit.h>
#include <gwenhywfar/debug.h>
#include <sys/socket.h>
#include <errno.h>
#include <string.h>
@@ -109,14 +114,59 @@ int AQH_FdObject_GetFd(const AQH_OBJECT *o)
int AQH_FdObject_Read(AQH_OBJECT *o, uint8_t *ptrBuffer, uint32_t lenBuffer)
{
if (o && ptrBuffer && lenBuffer) {
AQH_FDOBJECT *xo;
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
if (xo) {
if (xo->fd!=-1) {
ssize_t rv;
rv=recv(xo->fd, ptrBuffer, lenBuffer, MSG_DONTWAIT);
if (rv==0) {
DBG_INFO(AQH_LOGDOMAIN, "EOF met");
return 0;
}
else if (rv>0) {
/* data received */
return (int) rv;
}
else {
if (rv==EINTR || errno==EWOULDBLOCK || errno==EAGAIN) {
/* temporarily no data, try again */
return GWEN_ERROR_TRY_AGAIN;
}
else {
DBG_ERROR(AQH_LOGDOMAIN, "Error on read: %s (%d)", strerror(errno), errno);
xo->fd=-1;
return GWEN_ERROR_IO;
}
}
}
else {
DBG_ERROR(AQH_LOGDOMAIN, "Previous error, not reading.");
return GWEN_ERROR_IO;
}
}
}
return GWEN_ERROR_INVALID;
}
void _cbEnable(AQH_OBJECT *o)
{
if (o) {
if (o && !(AQH_Object_GetFlags(o) & AQH_OBJECT_FLAGS_ENABLED)) {
AQH_EVENT_LOOP *eventLoop;
eventLoop=AQH_Object_GetEventLoop(o);
if (eventLoop)
if (eventLoop) {
AQH_EventLoop_AddFdObject(eventLoop, o);
AQH_Object_AddFlags(o, AQH_OBJECT_FLAGS_ENABLED);
}
}
}
@@ -124,12 +174,14 @@ void _cbEnable(AQH_OBJECT *o)
void _cbDisable(AQH_OBJECT *o)
{
if (o) {
if (o && (AQH_Object_GetFlags(o) & AQH_OBJECT_FLAGS_ENABLED)) {
AQH_EVENT_LOOP *eventLoop;
eventLoop=AQH_Object_GetEventLoop(o);
if (eventLoop)
if (eventLoop) {
AQH_EventLoop_DelFdObject(eventLoop, o);
AQH_Object_SubFlags(o, AQH_OBJECT_FLAGS_ENABLED);
}
}
}