Created
December 31, 2016 20:06
-
-
Save malachib/3ff06a8a629ad863246b6e01a5d1510d to your computer and use it in GitHub Desktop.
Unexpected corruption
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct netconn *conn = netconn_new_with_proto_and_callback(NETCONN_UDP, 0, NULL); | |
char buf[512]; | |
if(!conn) | |
{ | |
cerr << "Failed to allocate socket"; | |
abort(); | |
} | |
netconn_bind(conn, IP_ADDR_ANY, 5000); | |
netconn_set_recvtimeout(conn, 0); // blocking | |
struct netbuf* nbFrom = netbuf_new(); | |
netconn_recv(conn, &nbFrom); | |
void* _recvBuf; | |
u16_t recvLen = 0; | |
const size_t offset = 50; | |
err_t err = netbuf_data(nbFrom, &_recvBuf, &recvLen); | |
clog << "Status: " << (uint16_t)err << endl; | |
clog << "Got " << recvLen << " bytes" << endl; | |
debugPrintBuffer((char*)_recvBuf, recvLen); | |
clog << endl; | |
memset(buf, 0, sizeof(buf)); | |
char* offsetbuf = buf + offset; | |
sprintf(offsetbuf, "Test send! (got: %d bytes)", recvLen); | |
size_t buflen = strlen(offsetbuf); | |
struct netbuf* nb = netbuf_new(); | |
netbuf_ref(nb, offsetbuf, buflen); | |
clog << "About to send" << endl; | |
clog << "buffer pre offset: "; | |
debugPrintBuffer((char*)buf, offset); | |
clog << endl; | |
netconn_sendto(conn, nb, netbuf_fromaddr(nbFrom), 5001); | |
clog << "buffer pre offset: "; | |
debugPrintBuffer((char*)buf, offset); | |
clog << endl; | |
clog << "Sent" << endl; | |
netbuf_delete(nb); | |
netbuf_delete(nbFrom); | |
netconn_disconnect(conn); | |
netconn_delete(conn); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perhaps it's cause I'm not waiting long enough for the TX async to complete sending, as alluded to here http://savannah.nongnu.org/bugs/?44805