Skip to content

Commit

Permalink
pass sendto userdata to incoming proc as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ghazel committed Sep 15, 2010
1 parent 0b30adb commit 43b0e2d
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyutp/utp/utp_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class UTPFunctionTable(ctypes.Structure):


# typedef void UTPGotIncomingConnection(UTPSocket* s);
UTPGotIncomingConnection = ctypes.CFUNCTYPE(None, ctypes.c_void_p)
UTPGotIncomingConnection = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_void_p)

# typedef void SendToProc(void *userdata, const byte *p, size_t len, const struct sockaddr *to, socklen_t tolen);
SendToProc = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.POINTER(ctypes.c_byte), ctypes.c_size_t, LPSOCKADDR, socklen_t)
2 changes: 1 addition & 1 deletion pyutp/utp/utp_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def on_overhead(self, send, count, type):


def wrap_incoming(f, send_to_proc):
def unwrap_incoming(utp_socket):
def unwrap_incoming(userdata, utp_socket):
us = Socket()
us.set_socket(utp_socket, send_to_proc)
f(us)
Expand Down
8 changes: 2 additions & 6 deletions tests/test_transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,9 @@ int ComparePacketTimestamp(TestUdpOutgoing* const* lhs, TestUdpOutgoing* const*
return (*lhs)->timestamp - (*rhs)->timestamp;
}

// HACK
test_manager* incoming_userdata = NULL;

void test_incoming_proc(UTPSocket* conn)
void test_incoming_proc(void *userdata, UTPSocket* conn)
{
incoming_userdata->IncomingUTP(conn);
((test_manager*)userdata)->IncomingUTP(conn);
}

void test_send_to_proc(void *userdata, const byte *p, size_t len, const struct sockaddr *to, socklen_t tolen)
Expand All @@ -154,7 +151,6 @@ void test_manager::Flush(uint32 start_time, uint32 max_time)

if (_receiver) {
// Lookup the right UTP socket that can handle this message
incoming_userdata = this;
UTP_IsIncomingUTP(&test_incoming_proc, &test_send_to_proc, _receiver, uo->mem, uo->len,
(const struct sockaddr*)&uo->addr, uo->addrlen);
}
Expand Down
2 changes: 1 addition & 1 deletion utp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2624,7 +2624,7 @@ bool UTP_IsIncomingUTP(UTPGotIncomingConnection *incoming_proc,
LOG_UTPV("0x%08x: recv send connect ACK", conn);
conn->send_ack(true);

incoming_proc(conn);
incoming_proc(send_to_userdata, conn);

// we report overhead after incoming_proc, because the callbacks are setup now
if (conn->userdata) {
Expand Down
2 changes: 1 addition & 1 deletion utp.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct UTPFunctionTable {

// The uTP socket layer calls this when a new incoming uTP connection is established
// this implies writability
typedef void UTPGotIncomingConnection(struct UTPSocket* s);
typedef void UTPGotIncomingConnection(void *userdata, struct UTPSocket* s);

// The uTP socket layer calls this to send UDP packets
typedef void SendToProc(void *userdata, const byte *p, size_t len, const struct sockaddr *to, socklen_t tolen);
Expand Down
2 changes: 1 addition & 1 deletion utp_file/utp_recv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void utp_overhead(void *socket, bool send, size_t count, int type)
{
}

void got_incoming_connection(UTPSocket *socket)
void got_incoming_connection(void *userdata, UTPSocket *socket)
{
printf("got incoming conenction: %p\n", socket);
assert(!utp_socket);
Expand Down
2 changes: 1 addition & 1 deletion utp_test/utp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void send_to(void *userdata, const byte *p, size_t len, const struct sockaddr *t
((UDPSocketManager*)userdata)->Send(p, len, to, tolen);
}

void got_incoming_connection(UTPSocket* s)
void got_incoming_connection(void *userdata, UTPSocket* s)
{
printf("incoming socket %p\n", s);
socket_state sock;
Expand Down

0 comments on commit 43b0e2d

Please sign in to comment.