* drv/dgram_pipe.c
* - Connection+Datagram based local IPC
*/
-#define DEBUG 1
+#define DEBUG 0
#include <vfs.h>
#include <fs_devfs.h>
#include <modules.h>
// - Root
tVFS_Node *IPCPipe_Root_MkNod(tVFS_Node *Node, const char *Name, Uint Flags);
int IPCPipe_Root_ReadDir(tVFS_Node *Node, int ID, char Name[FILENAME_MAX]);
-tVFS_Node *IPCPipe_Root_FindDir(tVFS_Node *Node, const char *Name);
+tVFS_Node *IPCPipe_Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags);
// - Server
int IPCPipe_Server_ReadDir(tVFS_Node *Node, int ID, char Name[FILENAME_MAX]);
-tVFS_Node *IPCPipe_Server_FindDir(tVFS_Node *Node, const char *Name);
+tVFS_Node *IPCPipe_Server_FindDir(tVFS_Node *Node, const char *Name, Uint Flags);
void IPCPipe_Server_Close(tVFS_Node *Node);
// - Socket
tIPCPipe_Channel *IPCPipe_int_GetEPs(tVFS_Node *Node, tIPCPipe_Endpoint **lep, tIPCPipe_Endpoint **rep);
-size_t IPCPipe_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Dest);
-size_t IPCPipe_Client_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Src);
+size_t IPCPipe_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Dest, Uint Flags);
+size_t IPCPipe_Client_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Src, Uint Flags);
void IPCPipe_Client_Close(tVFS_Node *Node);
// === GLOBALS ===
/**
* \return New client pointer
*/
-tVFS_Node *IPCPipe_Root_FindDir(tVFS_Node *Node, const char *Name)
+tVFS_Node *IPCPipe_Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags)
{
tIPCPipe_Server *srv;
ENTER("pNode sName", Node, Name);
return NULL;
}
+ if( Flags & VFS_FDIRFLAG_STAT ) {
+ // LEAVE('p', srv->TplClientNode);
+ // return &srv->TplClientNode;
+ }
+
// Create new client
- tIPCPipe_Channel *new_client;
-
+ tIPCPipe_Channel *new_client;
+
new_client = calloc(1, sizeof(tIPCPipe_Channel));
new_client->Server = srv;
new_client->ClientEP.Node.Type = &gIPCPipe_ChannelNodeType;
// 'next' is a valid entry, but readdir should never be called on this node
return -1;
}
-tVFS_Node *IPCPipe_Server_FindDir(tVFS_Node *Node, const char *Name)
+tVFS_Node *IPCPipe_Server_FindDir(tVFS_Node *Node, const char *Name, Uint Flags)
{
tIPCPipe_Server *srv = Node->ImplPtr;
return NULL;
}
+ // TODO: Need VFS_FDIRFLAG_NOBLOCK?
VFS_SelectNode(Node, VFS_SELECT_READ, 0, "IPCPipe Server");
tIPCPipe_Channel *conn;
}
return ch;
}
-size_t IPCPipe_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Dest)
+size_t IPCPipe_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Dest, Uint Flags)
{
tIPCPipe_Endpoint *lep, *rep;
tIPCPipe_Channel *channel = IPCPipe_int_GetEPs(Node, &lep, &rep);
}
// Wait for a packet to be ready
- VFS_SelectNode(Node, VFS_SELECT_READ, 0, "IPCPipe Endpoint");
+ tTime timeout_z = 0, *timeout = ((Flags & VFS_IOFLAG_NOBLOCK) ? &timeout_z : NULL);
+ int rv = VFS_SelectNode(Node, VFS_SELECT_READ, timeout, "IPCPipe Endpoint");
+ if( !rv ) {
+ errno = (Flags & VFS_IOFLAG_NOBLOCK) ? EWOULDBLOCK : EINTR;
+ LEAVE('i', -1);
+ return -1;
+ }
if( channel->Server == NULL ) {
+ //errno = EIO;
LEAVE('i', -1);
return -1;
}
if( !rep->Node.ImplPtr )
{
Mutex_Release(&rep->lList);
+ //errno = EIO;
LEAVE('i', -1);
return -1;
}
return ret;
}
-size_t IPCPipe_Client_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Src)
+size_t IPCPipe_Client_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Src, Uint Flags)
{
tIPCPipe_Endpoint *lep, *rep;
tIPCPipe_Channel *channel = IPCPipe_int_GetEPs(Node, &lep, &rep);
return 0;
}
- // Create packet structure
+ // TODO: Ensure that no more than DEF_MAX_BYTE_LIMIT bytes are in flight at one time
+
+ // Create packet structure
tIPCPipe_Packet *pkt = malloc(sizeof(tIPCPipe_Packet)+Length);
pkt->Next = NULL;
pkt->Offset = 0;