X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FIPStack%2Fudp.c;h=40e6474f9395d755267a3cb600edfae971021929;hb=5dc3cea45b3cb43e26a6ed51e98f923a9fd73d92;hp=8b0904c24a4dc5cc583104ed127b6d922b23e704;hpb=849329d50395b44ac97c5b5145fc2df0749eace2;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/IPStack/udp.c b/KernelLand/Modules/IPStack/udp.c index 8b0904c2..40e6474f 100644 --- a/KernelLand/Modules/IPStack/udp.c +++ b/KernelLand/Modules/IPStack/udp.c @@ -15,8 +15,8 @@ void UDP_Unreachable(tInterface *Interface, int Code, void *Address, int Length, void UDP_SendPacketTo(tUDPChannel *Channel, int AddrType, const void *Address, Uint16 Port, const void *Data, size_t Length); // --- Client Channels tVFS_Node *UDP_Channel_Init(tInterface *Interface); -size_t UDP_Channel_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); -size_t UDP_Channel_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer); +size_t UDP_Channel_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); +size_t UDP_Channel_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags); int UDP_Channel_IOCtl(tVFS_Node *Node, int ID, void *Data); void UDP_Channel_Close(tVFS_Node *Node); // --- Helpers @@ -117,10 +117,8 @@ void UDP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe { tUDPHeader *hdr = Buffer; - Log_Debug("UDP", "hdr->SourcePort = %i", ntohs(hdr->SourcePort)); - Log_Debug("UDP", "hdr->DestPort = %i", ntohs(hdr->DestPort)); - Log_Debug("UDP", "hdr->Length = %i", ntohs(hdr->Length)); - Log_Debug("UDP", "hdr->Checksum = 0x%x", ntohs(hdr->Checksum)); + Log_Debug("UDP", "%i bytes :%i->:%i (Cksum 0x%04x)", + ntohs(hdr->Length), ntohs(hdr->SourcePort), ntohs(hdr->Length), ntohs(hdr->Checksum)); // Check registered connections Mutex_Acquire(&glUDP_Channels); @@ -189,7 +187,7 @@ tVFS_Node *UDP_Channel_Init(tInterface *Interface) /** * \brief Read from the channel file (wait for a packet) */ -size_t UDP_Channel_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t UDP_Channel_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { tUDPChannel *chan = Node->ImplPtr; tUDPPacket *pack; @@ -205,7 +203,11 @@ size_t UDP_Channel_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buff for(;;) { - VFS_SelectNode(Node, VFS_SELECT_READ, NULL, "UDP_Channel_Read"); + tTime timeout_z = 0, *timeout = (Flags & VFS_IOFLAG_NOBLOCK) ? &timeout_z : NULL; + int rv = VFS_SelectNode(Node, VFS_SELECT_READ, timeout, "UDP_Channel_Read"); + if( rv ) { + errno = (Flags & VFS_IOFLAG_NOBLOCK) ? EWOULDBLOCK : EINTR; + } SHORTLOCK(&chan->lQueue); if(chan->Queue == NULL) { SHORTREL(&chan->lQueue); @@ -249,13 +251,17 @@ size_t UDP_Channel_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buff /** * \brief Write to the channel file (send a packet) */ -size_t UDP_Channel_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer) +size_t UDP_Channel_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags) { tUDPChannel *chan = Node->ImplPtr; const tUDPEndpoint *ep; const void *data; int ofs; - if(chan->LocalPort == 0) return 0; + + if(chan->LocalPort == 0) { + Log_Notice("UDP", "Write to channel %p with zero local port", chan); + return 0; + } ep = Buffer; ofs = 2 + 2 + IPStack_GetAddressSize( ep->AddrType ); @@ -264,7 +270,7 @@ size_t UDP_Channel_Write(tVFS_Node *Node, off_t Offset, size_t Length, const voi UDP_SendPacketTo(chan, ep->AddrType, &ep->Addr, ep->Port, data, (size_t)Length - ofs); - return 0; + return Length; } /**