Net: the wire seam -- file-local Winsock primitive wrappers (step 4a)
BTNetSend/Recv/Accept/Close wrap the 9 raw wire sites in L4NET.CPP (send @x3, recv, accept @x2, closesocket @x2). OFF builds are PURE CODE MOTION (bodies are the original calls; the statics inline back); under BT_STEAM each wrapper first offers the op to the Steam transport (BTSteamNet_*, lands next) -- handles stay SOCKET-typed so L4Host and every call site above the seam are identical on both wires. Connection-ESTABLISHMENT delegates (OpenConnection/listener arms) land with the transport. The 3 BT_NET_TRACE blocks stay at call-site level, untouched. Regression (pod build, 2-node loopback MP + btconsole relay): mesh forms through BTNetAccept (console + peer accepts logged), both nodes reach the full 31/31-subsystem running mission, 71/76 ticks -- byte-identical wire behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,77 @@
|
||||
#include "..\munga\notation.h"
|
||||
//#include <netnub.hpp>
|
||||
|
||||
//===========================================================================//
|
||||
// The WIRE SEAM (glass-cockpit step 4a).
|
||||
//
|
||||
// File-local wrappers around the raw Winsock wire primitives. With
|
||||
// BT_STEAM off (the pod and plain glass builds) these are PURE CODE
|
||||
// MOTION -- each body is the original inline call, and the compiler
|
||||
// inlines the static right back; wire bytes are untouched. Under
|
||||
// BT_STEAM each wrapper first offers the operation to the Steam transport
|
||||
// (L4STEAMNET), which owns a connection when the lobby registered it --
|
||||
// handles stay SOCKET-typed (HSteamNetConnection is a u32) so L4Host and
|
||||
// every call site above the seam are identical on both wires.
|
||||
//
|
||||
// The connection-ESTABLISHMENT delegates (OpenConnection / the listener
|
||||
// arms) land with the Steam transport itself; these are the per-packet
|
||||
// primitives every transport must intercept.
|
||||
//===========================================================================//
|
||||
|
||||
#ifdef BT_STEAM
|
||||
#include "l4steamnet.h"
|
||||
#endif
|
||||
|
||||
static int
|
||||
BTNetSend(SOCKET wire_socket, const char *data, int length)
|
||||
{
|
||||
#ifdef BT_STEAM
|
||||
if (BTSteamNet_Owns(wire_socket))
|
||||
{
|
||||
return BTSteamNet_Send(wire_socket, data, length);
|
||||
}
|
||||
#endif
|
||||
return send(wire_socket, data, length, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
BTNetRecv(SOCKET wire_socket, char *buffer, int capacity)
|
||||
{
|
||||
#ifdef BT_STEAM
|
||||
if (BTSteamNet_Owns(wire_socket))
|
||||
{
|
||||
return BTSteamNet_Recv(wire_socket, buffer, capacity);
|
||||
}
|
||||
#endif
|
||||
return recv(wire_socket, buffer, capacity, 0);
|
||||
}
|
||||
|
||||
static SOCKET
|
||||
BTNetAccept(SOCKET listener_socket)
|
||||
{
|
||||
#ifdef BT_STEAM
|
||||
SOCKET steam_socket = BTSteamNet_Accept(listener_socket);
|
||||
if (steam_socket != INVALID_SOCKET)
|
||||
{
|
||||
return steam_socket;
|
||||
}
|
||||
#endif
|
||||
return accept(listener_socket, NULL, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
BTNetClose(SOCKET wire_socket)
|
||||
{
|
||||
#ifdef BT_STEAM
|
||||
if (BTSteamNet_Owns(wire_socket))
|
||||
{
|
||||
BTSteamNet_Close(wire_socket);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
closesocket(wire_socket);
|
||||
}
|
||||
|
||||
|
||||
#if defined(TRACE_SEND_PACKET)
|
||||
static BitTrace Send_Packet("Send Packet");
|
||||
@@ -1146,7 +1217,7 @@ void L4NetworkManager::Send(
|
||||
//Net_Common_Ptr->Buffer_Length = (short)SEND_BUFFER_SIZE(packet_size);
|
||||
//send_packet_request->Socket_Ptr = l4host->GetNetworkSocket();
|
||||
//NetNub::SendCommand();
|
||||
send(l4host->GetNetworkSocket(), (char *)my_temp_packet, packet_size, 0);
|
||||
BTNetSend(l4host->GetNetworkSocket(), (char *)my_temp_packet, packet_size);
|
||||
free(my_temp_packet);
|
||||
// Check for errors and abort if there were any
|
||||
//#if defined(TRACE_SEND_BUFFER)
|
||||
@@ -1325,7 +1396,7 @@ Logical L4NetworkManager::SendMessageToNetnub(
|
||||
<< " len=" << (int)message->messageLength
|
||||
<< " -> host " << (int)host_ID << "\n" << std::flush;
|
||||
}
|
||||
send(receiving_host->GetNetworkSocket(), (char *)network_packet, munga_network_message_size, 0);
|
||||
BTNetSend(receiving_host->GetNetworkSocket(), (char *)network_packet, munga_network_message_size);
|
||||
free(network_packet);
|
||||
|
||||
#if defined(TRACE_SEND_BUFFER)
|
||||
@@ -1871,7 +1942,7 @@ void
|
||||
//NetNub::SendCommand();
|
||||
for(int i=0; i<host_count; i++)
|
||||
{
|
||||
send(l4host_array[i]->GetNetworkSocket(), (char *)network_packet, sizeof(network_packet), 0);
|
||||
BTNetSend(l4host_array[i]->GetNetworkSocket(), (char *)network_packet, sizeof(network_packet));
|
||||
}
|
||||
free(network_packet);
|
||||
|
||||
@@ -2112,15 +2183,15 @@ Logical L4NetworkManager::CheckBuffers(NetworkPacket *network_packet)
|
||||
|
||||
if(remote_host->GetHostType() == ConsoleHostType)
|
||||
{
|
||||
if((tempSocket = accept(consoleListenerSocket, NULL, 0)) != INVALID_SOCKET)
|
||||
if((tempSocket = BTNetAccept(consoleListenerSocket)) != INVALID_SOCKET)
|
||||
{
|
||||
closesocket(consoleListenerSocket);
|
||||
BTNetClose(consoleListenerSocket);
|
||||
consoleListenerSocket = INVALID_SOCKET;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if((tempSocket = accept(gameListenerSocket, NULL, 0)) == INVALID_SOCKET)
|
||||
if((tempSocket = BTNetAccept(gameListenerSocket)) == INVALID_SOCKET)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -2256,7 +2327,7 @@ Logical L4NetworkManager::CheckBuffers(NetworkPacket *network_packet)
|
||||
// call the network server
|
||||
//NetShare();
|
||||
void* buffer = malloc(space_left);
|
||||
int received = recv(remote_host->GetNetworkSocket(), (char*)buffer, space_left, 0);
|
||||
int received = BTNetRecv(remote_host->GetNetworkSocket(), (char*)buffer, space_left);
|
||||
// if we received data, copy it over into the buffer for this host
|
||||
//switch(Net_Common_Ptr->Status)
|
||||
if(received > 0)
|
||||
@@ -2907,7 +2978,7 @@ void L4NetworkManager::CloseConnection(SOCKET socket_ptr) // socket address fro
|
||||
//close_request->Socket_Ptr = socket_ptr;
|
||||
//NetNub::SendCommand();
|
||||
shutdown(socket_ptr, SD_BOTH);
|
||||
closesocket(socket_ptr);
|
||||
BTNetClose(socket_ptr);
|
||||
// Check for errors
|
||||
//if(Net_Common_Ptr->Status != NETNUB_OK)
|
||||
//{
|
||||
|
||||
Reference in New Issue
Block a user