FreeNOS
UDPFactory.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "UDP.h"
19#include "UDPFactory.h"
20#include "UDPSocket.h"
21
23 UDP *udp)
24 : File(inode)
25 , m_udp(udp)
26{
27}
28
32
34 Size & size,
35 const Size offset)
36{
37 DEBUG("");
38
39 String path;
40 UDPSocket *sock;
41 const FileSystemMessage *msg = buffer.getMessage();
42
43 if (offset > 0)
44 {
45 size = 0;
47 }
48
49 sock = m_udp->createSocket(path, msg->from);
50 if (!sock)
51 {
52 ERROR("failed to create UDP socket");
54 }
55
56 buffer.write(*path, path.length() + 1);
57 size = path.length() + 1;
59}
ProcessID from
Source process of the message.
Represents a file present on a FileSystem.
Definition File.h:40
Abstract Input/Output buffer.
Definition IOBuffer.h:38
FileSystem::Result write(const void *buffer, const Size size, const Size offset=ZERO)
Write bytes to the I/O buffer.
Definition IOBuffer.cpp:180
const FileSystemMessage * getMessage() const
Get filesystem message.
Definition IOBuffer.cpp:120
Abstraction of strings.
Definition String.h:42
Size length() const
Same as count().
Definition String.cpp:105
UDPFactory(const u32 inode, UDP *udp)
Constructor.
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Create UDP socket.
UDP * m_udp
UDP protocol instance.
Definition UDPFactory.h:73
virtual ~UDPFactory()
Destructor.
User Datagram Protocol (UDP) socket.
Definition UDPSocket.h:43
User Datagram Protocol (UDP)
Definition UDP.h:42
UDPSocket * createSocket(String &path, const ProcessID pid)
Creates an UDP socket.
Definition UDP.cpp:47
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
#define ERROR(msg)
Output an error message.
Definition Log.h:61
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
#define DEBUG(msg)
Output a debug message to standard output.
Definition Log.h:89
Result
Result code for filesystem Actions.
Definition FileSystem.h:53
FileSystem IPC message.