mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2024-12-29 08:46:31 +00:00
2ea6956433
Restructure network stack to use new Interrupt methods instead of hard-coded IRQ numbers. Add line count update into build process. Add progress bars to HTML generation and DoDistro. Clear Network Log border_doc. Fix font chars. Clean up some lingering unconverted variable and directory names. Remove word-wrap DolDoc tag from Clementine bible because of CPU spikes.
254 lines
18 KiB
HTML
Executable file
254 lines
18 KiB
HTML
Executable file
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
|
|
<meta name="generator" content="ZealOS V0.07">
|
|
<style type="text/css">
|
|
body {background-color:#000000;}
|
|
.cF0{color:#ffffff;background-color:#000000;}
|
|
.cF1{color:#3465a4;background-color:#000000;}
|
|
.cF2{color:#4e9a06;background-color:#000000;}
|
|
.cF3{color:#06989a;background-color:#000000;}
|
|
.cF4{color:#a24444;background-color:#000000;}
|
|
.cF5{color:#75507b;background-color:#000000;}
|
|
.cF6{color:#ce982f;background-color:#000000;}
|
|
.cF7{color:#bcc0b9;background-color:#000000;}
|
|
.cF8{color:#555753;background-color:#000000;}
|
|
.cF9{color:#729fcf;background-color:#000000;}
|
|
.cFA{color:#82bc49;background-color:#000000;}
|
|
.cFB{color:#34e2e2;background-color:#000000;}
|
|
.cFC{color:#ac3535;background-color:#000000;}
|
|
.cFD{color:#ad7fa8;background-color:#000000;}
|
|
.cFE{color:#fce94f;background-color:#000000;}
|
|
.cFF{color:#000000;background-color:#000000;}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<pre style="font-family:monospace;font-size:12pt">
|
|
<a name="l1"></a><span class=cF0>CTCPSocket *tcp = TCPSocket(AF_INET);
|
|
<a name="l2"></a>CTCPTreeQueue *connections = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CTCPTreeQueue</span><span class=cF7>)</span><span class=cF0>); </span><span class=cF2>// head</span><span class=cF0>
|
|
<a name="l3"></a></span><span class=cF1>U8</span><span class=cF0> *buffer = </span><span class=cF5>CAlloc</span><span class=cF0>(ETHERNET_FRAME_SIZE);
|
|
<a name="l4"></a>
|
|
<a name="l5"></a></span><span class=cF5>QueueInit</span><span class=cF0>(connections);
|
|
<a name="l6"></a>
|
|
<a name="l7"></a></span><span class=cF1>U0</span><span class=cF0> ChatServerKill()
|
|
<a name="l8"></a>{
|
|
<a name="l9"></a> CTCPTreeQueue *conn = connections->next;
|
|
<a name="l10"></a> CTCPTreeQueue *next_conn;
|
|
<a name="l11"></a>
|
|
<a name="l12"></a> </span><span class=cF1>while</span><span class=cF0> (conn != connections)
|
|
<a name="l13"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l14"></a> </span><span class=cF6>"\nClosing socket @ 0x%0X\n"</span><span class=cF0>, conn->socket;
|
|
<a name="l15"></a> TCPSocketClose(conn->socket);
|
|
<a name="l16"></a> next_conn = conn->next;
|
|
<a name="l17"></a> </span><span class=cF5>Free</span><span class=cF0>(conn);
|
|
<a name="l18"></a> conn = next_conn;
|
|
<a name="l19"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l20"></a>
|
|
<a name="l21"></a> </span><span class=cF6>"\nClosing listening socket.\n"</span><span class=cF0>;
|
|
<a name="l22"></a> TCPSocketClose(tcp);
|
|
<a name="l23"></a>
|
|
<a name="l24"></a> </span><span class=cF1>return</span><span class=cF0>;
|
|
<a name="l25"></a>}
|
|
<a name="l26"></a>
|
|
<a name="l27"></a></span><span class=cF1>U0</span><span class=cF0> ChatServerBroadcast(CTCPSocket *tcp_socket, </span><span class=cF9>I64</span><span class=cF0> length)
|
|
<a name="l28"></a>{ </span><span class=cF2>// Broadcast length bytes of msg in buffer to all but original socket.</span><span class=cF0>
|
|
<a name="l29"></a> CTCPTreeQueue *conn = connections->next;
|
|
<a name="l30"></a> CTCPSocket *dest_socket;
|
|
<a name="l31"></a> </span><span class=cF1>U8</span><span class=cF0> *ip_string;
|
|
<a name="l32"></a> CIPV4Address addr;
|
|
<a name="l33"></a> </span><span class=cF1>U8</span><span class=cF0> *message;
|
|
<a name="l34"></a> </span><span class=cF1>U8</span><span class=cF0> *message_prefix;
|
|
<a name="l35"></a>
|
|
<a name="l36"></a> </span><span class=cF1>while</span><span class=cF0> (conn != connections)
|
|
<a name="l37"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l38"></a> dest_socket = conn->socket;
|
|
<a name="l39"></a>
|
|
<a name="l40"></a> </span><span class=cF1>if</span><span class=cF0> (dest_socket != tcp_socket)
|
|
<a name="l41"></a> {
|
|
<a name="l42"></a> addr.address = </span><span class=cF5>EndianU32</span><span class=cF0>(dest_socket->destination_address</span><span class=cF7>(</span><span class=cF0>CSocketAddressIPV4</span><span class=cF7>)</span><span class=cF0>.address.address);
|
|
<a name="l43"></a>
|
|
<a name="l44"></a> ip_string = NetworkToPresentation(AF_INET, &addr);
|
|
<a name="l45"></a> </span><span class=cF2>// TODO: is NetworkToPresentation backwards? or, do socket addrs store BE or LE ?</span><span class=cF0>
|
|
<a name="l46"></a>
|
|
<a name="l47"></a> </span><span class=cF6>"\nBroacasting msg to %s.\n"</span><span class=cF0>, ip_string;
|
|
<a name="l48"></a>
|
|
<a name="l49"></a> addr.address = </span><span class=cF5>EndianU32</span><span class=cF0>(tcp_socket->destination_address</span><span class=cF7>(</span><span class=cF0>CSocketAddressIPV4</span><span class=cF7>)</span><span class=cF0>.address.address);
|
|
<a name="l50"></a>
|
|
<a name="l51"></a> ip_string = NetworkToPresentation(AF_INET, &addr);
|
|
<a name="l52"></a> </span><span class=cF2>// TODO: is NetworkToPresentation backwards? or, do socket addrs store BE or LE ?</span><span class=cF0>
|
|
<a name="l53"></a>
|
|
<a name="l54"></a> message_prefix = </span><span class=cF5>MStrPrint</span><span class=cF0>(</span><span class=cF6>"$BG,PURPLE$$BLACK$<%s>$FG$$BG$ %%0%dts"</span><span class=cF0>, ip_string, length);
|
|
<a name="l55"></a>
|
|
<a name="l56"></a> message = </span><span class=cF5>MStrPrint</span><span class=cF0>(message_prefix, buffer);
|
|
<a name="l57"></a>
|
|
<a name="l58"></a> TCPSocketSendString(dest_socket, message);
|
|
<a name="l59"></a>
|
|
<a name="l60"></a> </span><span class=cF5>Free</span><span class=cF0>(message);
|
|
<a name="l61"></a> </span><span class=cF5>Free</span><span class=cF0>(message_prefix);
|
|
<a name="l62"></a> </span><span class=cF5>Free</span><span class=cF0>(ip_string);
|
|
<a name="l63"></a>
|
|
<a name="l64"></a> }
|
|
<a name="l65"></a>
|
|
<a name="l66"></a> conn = conn->next;
|
|
<a name="l67"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l68"></a>
|
|
<a name="l69"></a> </span><span class=cF1>return</span><span class=cF0>;
|
|
<a name="l70"></a>}
|
|
<a name="l71"></a>
|
|
<a name="l72"></a></span><span class=cF1>U0</span><span class=cF0> ChatServerBroadcastDisconnect()
|
|
<a name="l73"></a>{
|
|
<a name="l74"></a> CTCPTreeQueue *conn = connections->next;
|
|
<a name="l75"></a> CTCPSocket *conn_socket;
|
|
<a name="l76"></a> </span><span class=cF1>U8</span><span class=cF0> *message = </span><span class=cF5>MStrPrint</span><span class=cF0>(</span><span class=cF6>"$BG,LTGRAY$$DKGRAY$Client disconnected. Connected clients: %d$FG$$BG$"</span><span class=cF0>,
|
|
<a name="l77"></a> </span><span class=cF5>QueueCount</span><span class=cF7>(</span><span class=cF0>connections</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l78"></a> </span><span class=cF1>while</span><span class=cF0> (conn != connections)
|
|
<a name="l79"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l80"></a> conn_socket = conn->socket;
|
|
<a name="l81"></a>
|
|
<a name="l82"></a> TCPSocketSendString(conn_socket, message);
|
|
<a name="l83"></a>
|
|
<a name="l84"></a> conn = conn->next;
|
|
<a name="l85"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l86"></a>
|
|
<a name="l87"></a> </span><span class=cF5>Free</span><span class=cF0>(message);
|
|
<a name="l88"></a>
|
|
<a name="l89"></a>}
|
|
<a name="l90"></a>
|
|
<a name="l91"></a></span><span class=cF1>U0</span><span class=cF0> ChatServerReceive()
|
|
<a name="l92"></a>{
|
|
<a name="l93"></a> CTCPTreeQueue *conn = connections->next;
|
|
<a name="l94"></a> CTCPTreeQueue *next_conn;
|
|
<a name="l95"></a> CTCPSocket *socket;
|
|
<a name="l96"></a> </span><span class=cF9>I64</span><span class=cF0> message_len;
|
|
<a name="l97"></a> </span><span class=cF1>U8</span><span class=cF0> *ip_string;
|
|
<a name="l98"></a> CIPV4Address addr;
|
|
<a name="l99"></a>
|
|
<a name="l100"></a>
|
|
<a name="l101"></a> </span><span class=cF1>while</span><span class=cF0> (conn != connections)
|
|
<a name="l102"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l103"></a> socket = conn->socket;
|
|
<a name="l104"></a> message_len = TCPSocketReceive(socket, buffer, ETHERNET_FRAME_SIZE);
|
|
<a name="l105"></a>
|
|
<a name="l106"></a> </span><span class=cF1>if</span><span class=cF0> (message_len == </span><span class=cFE>0</span><span class=cF0>)
|
|
<a name="l107"></a> {
|
|
<a name="l108"></a> </span><span class=cF6>"\nClosing a connection.\n"</span><span class=cF0>;
|
|
<a name="l109"></a> socket->timeout = TCP_TIMEOUT;
|
|
<a name="l110"></a> TCPSocketClose(socket);
|
|
<a name="l111"></a>
|
|
<a name="l112"></a> next_conn = conn->next;
|
|
<a name="l113"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(conn);
|
|
<a name="l114"></a> </span><span class=cF5>Free</span><span class=cF0>(conn);
|
|
<a name="l115"></a> conn = next_conn;
|
|
<a name="l116"></a>
|
|
<a name="l117"></a> ChatServerBroadcastDisconnect();
|
|
<a name="l118"></a>
|
|
<a name="l119"></a> }
|
|
<a name="l120"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (message_len > </span><span class=cFE>0</span><span class=cF0>)
|
|
<a name="l121"></a> {
|
|
<a name="l122"></a> addr.address = </span><span class=cF5>EndianU32</span><span class=cF0>(socket->destination_address</span><span class=cF7>(</span><span class=cF0>CSocketAddressIPV4</span><span class=cF7>)</span><span class=cF0>.address.address);
|
|
<a name="l123"></a>
|
|
<a name="l124"></a> ip_string = NetworkToPresentation(AF_INET, &addr);
|
|
<a name="l125"></a> </span><span class=cF2>// TODO: is NetworkToPresentation backwards? or, do socket addrs store BE or LE ?</span><span class=cF0>
|
|
<a name="l126"></a>
|
|
<a name="l127"></a> </span><span class=cF6>"\nBroadcasting %d byte msg from %s: %Q\n"</span><span class=cF0>, message_len, ip_string, buffer;
|
|
<a name="l128"></a>
|
|
<a name="l129"></a> </span><span class=cF2>//ClassRep(socket);</span><span class=cF0>
|
|
<a name="l130"></a> ChatServerBroadcast(socket, message_len);
|
|
<a name="l131"></a> </span><span class=cF5>MemSet</span><span class=cF0>(buffer, </span><span class=cFE>0</span><span class=cF0>, ETHERNET_FRAME_SIZE);
|
|
<a name="l132"></a> conn = conn->next;
|
|
<a name="l133"></a> }
|
|
<a name="l134"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l135"></a> {
|
|
<a name="l136"></a> </span><span class=cF2>//"\nReceived -1 [error], trying next connection.\n";</span><span class=cF0>
|
|
<a name="l137"></a> conn = conn->next;
|
|
<a name="l138"></a> }
|
|
<a name="l139"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l140"></a>
|
|
<a name="l141"></a> </span><span class=cF1>return</span><span class=cF0>;
|
|
<a name="l142"></a>
|
|
<a name="l143"></a>}
|
|
<a name="l144"></a>
|
|
<a name="l145"></a></span><span class=cF1>U0</span><span class=cF0> ChatServer()
|
|
<a name="l146"></a>{
|
|
<a name="l147"></a> CSocketAddressIPV4 socket_addr;
|
|
<a name="l148"></a> </span><span class=cF1>U8</span><span class=cF0> *port_string = </span><span class=cF5>StrGet</span><span class=cF0>(</span><span class=cF6>"Server Port: "</span><span class=cF0>);
|
|
<a name="l149"></a> </span><span class=cF9>I64</span><span class=cF0> port = </span><span class=cF5>Str2I64</span><span class=cF0>(port_string);
|
|
<a name="l150"></a> CTCPSocket *new_socket;
|
|
<a name="l151"></a> CTCPTreeQueue *new_conn;
|
|
<a name="l152"></a> </span><span class=cF1>U8</span><span class=cF0> *join_msg;
|
|
<a name="l153"></a> CTCPTreeQueue *conn;
|
|
<a name="l154"></a> CTCPSocket *conn_socket;
|
|
<a name="l155"></a>
|
|
<a name="l156"></a>
|
|
<a name="l157"></a> </span><span class=cF5>Free</span><span class=cF0>(port_string);
|
|
<a name="l158"></a>
|
|
<a name="l159"></a> socket_addr.port = </span><span class=cF5>EndianU16</span><span class=cF0>(port);
|
|
<a name="l160"></a> socket_addr.family = AF_INET;
|
|
<a name="l161"></a> socket_addr.address.address = INADDR_ANY;
|
|
<a name="l162"></a>
|
|
<a name="l163"></a> tcp->timeout = </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>3</span><span class=cF0> * </span><span class=cF3>JIFFY_FREQ</span><span class=cF0>;
|
|
<a name="l164"></a>
|
|
<a name="l165"></a> </span><span class=cF6>"\nTrying to bind socket.\n"</span><span class=cF0>;
|
|
<a name="l166"></a> </span><span class=cF1>if</span><span class=cF0> (TCPSocketBind</span><span class=cF7>(</span><span class=cF0>tcp, &socket_addr</span><span class=cF7>)</span><span class=cF0> == </span><span class=cFE>0</span><span class=cF0>)
|
|
<a name="l167"></a> </span><span class=cF6>"\nSocket bound.\n"</span><span class=cF0>;
|
|
<a name="l168"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l169"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l170"></a> </span><span class=cF6>"\nFailed to bind socket.\n"</span><span class=cF0>;
|
|
<a name="l171"></a> ChatServerKill;
|
|
<a name="l172"></a> </span><span class=cF1>return</span><span class=cF0>;
|
|
<a name="l173"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l174"></a>
|
|
<a name="l175"></a> </span><span class=cF6>"\nTrying to listen on socket.\n"</span><span class=cF0>;
|
|
<a name="l176"></a> </span><span class=cF1>if</span><span class=cF0> (TCPSocketListen</span><span class=cF7>(</span><span class=cF0>tcp, </span><span class=cFE>5</span><span class=cF7>)</span><span class=cF0> == </span><span class=cFE>0</span><span class=cF0>)
|
|
<a name="l177"></a> </span><span class=cF6>"\nSocket now listening.\n"</span><span class=cF0>;
|
|
<a name="l178"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l179"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l180"></a> </span><span class=cF6>"\nFailed to listen on socket.\n"</span><span class=cF0>;
|
|
<a name="l181"></a> ChatServerKill;
|
|
<a name="l182"></a> </span><span class=cF1>return</span><span class=cF0>;
|
|
<a name="l183"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l184"></a>
|
|
<a name="l185"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>CharScan</span><span class=cF0> != </span><span class=cF3>CH_SHIFT_ESC</span><span class=cF0>)
|
|
<a name="l186"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l187"></a> new_socket = TCPSocketAccept(tcp);
|
|
<a name="l188"></a>
|
|
<a name="l189"></a> </span><span class=cF1>if</span><span class=cF0> (new_socket > </span><span class=cFE>0</span><span class=cF0>)
|
|
<a name="l190"></a> {
|
|
<a name="l191"></a> </span><span class=cF6>"\nNew connection.\n"</span><span class=cF0>;
|
|
<a name="l192"></a> new_conn = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CTCPTreeQueue</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l193"></a> new_conn->socket = new_socket;
|
|
<a name="l194"></a> new_socket->timeout = </span><span class=cFE>0</span><span class=cF0>; </span><span class=cF2>// Set new connection non-blocking.</span><span class=cF0>
|
|
<a name="l195"></a>
|
|
<a name="l196"></a> join_msg = </span><span class=cF5>MStrPrint</span><span class=cF0>(</span><span class=cF6>"$BG,LTGRAY$$DKGRAY$Connected clients: %d$FG$$BG$"</span><span class=cF0>, </span><span class=cF5>QueueCount</span><span class=cF7>(</span><span class=cF0>connections</span><span class=cF7>)</span><span class=cF0> + </span><span class=cFE>1</span><span class=cF0>);
|
|
<a name="l197"></a>
|
|
<a name="l198"></a> TCPSocketSendString(new_socket, join_msg);
|
|
<a name="l199"></a> </span><span class=cF5>Free</span><span class=cF0>(join_msg);
|
|
<a name="l200"></a>
|
|
<a name="l201"></a> join_msg = </span><span class=cF5>MStrPrint</span><span class=cF0>(</span><span class=cF6>"$BG,LTGRAY$$DKGRAY$New connection. Connected clients: %d$FG$$BG$"</span><span class=cF0>,
|
|
<a name="l202"></a> </span><span class=cF5>QueueCount</span><span class=cF7>(</span><span class=cF0>connections</span><span class=cF7>)</span><span class=cF0> + </span><span class=cFE>1</span><span class=cF0>);
|
|
<a name="l203"></a>
|
|
<a name="l204"></a> conn = connections->next;
|
|
<a name="l205"></a>
|
|
<a name="l206"></a> </span><span class=cF1>while</span><span class=cF0> (conn != connections)
|
|
<a name="l207"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l208"></a> </span><span class=cF6>"\nNotifying clients of new connection.\n"</span><span class=cF0>;
|
|
<a name="l209"></a> conn_socket = conn->socket;
|
|
<a name="l210"></a> TCPSocketSendString(conn_socket, join_msg);
|
|
<a name="l211"></a> conn = conn->next;
|
|
<a name="l212"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l213"></a> </span><span class=cF5>Free</span><span class=cF0>(join_msg);
|
|
<a name="l214"></a>
|
|
<a name="l215"></a> </span><span class=cF5>QueueInsertRev</span><span class=cF0>(new_conn, connections);
|
|
<a name="l216"></a> }
|
|
<a name="l217"></a>
|
|
<a name="l218"></a> ChatServerReceive; </span><span class=cF2>// Receive & Broadcast</span><span class=cF0>
|
|
<a name="l219"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>50</span><span class=cF0>);
|
|
<a name="l220"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l221"></a>
|
|
<a name="l222"></a>
|
|
<a name="l223"></a> ChatServerKill;
|
|
<a name="l224"></a>}
|
|
<a name="l225"></a>
|
|
<a name="l226"></a>ChatServer;</span></pre></body>
|
|
</html>
|