The Pedigree Project 0.1
lwip.cc
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include "pedigree/kernel/Log.h"
21#include "pedigree/kernel/process/Completion.h"
22
23#include "modules/Module.h"
27
28// Switch the module-specific pieces of the module over to hidden visibility
29#pragma GCC visibility push(hidden)
30
31static Completion tcpipInitPending;
32
33static void tcpipInitComplete(void*) {
34 tcpipInitPending.complete();
35}
36
37static err_t stopTcpip() {
38 err_t result = ERR_INPROGRESS;
39 while (result == ERR_INPROGRESS) {
40 result = tcpip_shutdown();
41 if (result == ERR_INPROGRESS) {
42 sys_msleep(1);
43 }
44 }
45 return result;
46}
47
48static bool entry() {
49 // make sure the multi threaded lwIP implementation is ready to go
51 tcpip_init(tcpipInitComplete, nullptr);
52
53 if (!tcpipInitPending.wait()) {
54 if (stopTcpip() != ERR_OK) {
55 FATAL("lwIP could not stop its tcpip worker after interrupted init");
56 }
57 return false;
58 }
59
60 return true;
61}
62
63static void exit() {
64 if (stopTcpip() != ERR_OK) {
65 FATAL("lwIP could not stop and join its tcpip worker");
66 }
67}
68
69MODULE_INFO("lwip", &entry, &exit);
bool complete()
Definition Completion.cc:43
MUST_USE_RESULT bool wait(WaitQueue::StackDiscardCleanup onStackDiscard=nullptr, void *stackDiscardContext=nullptr)
Definition Completion.cc:16
s8_t err_t
Definition err.h:76
@ ERR_INPROGRESS
Definition err.h:92
@ ERR_OK
Definition err.h:82
void sys_msleep(u32_t ms)
void tcpip_init(tcpip_init_done_fn initfunc, void *arg)
Definition tcpip.c:648
err_t tcpip_shutdown(void)
Definition tcpip.c:680