File tree Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -121,20 +121,25 @@ void UDP::write(const uint8_t *buffer, size_t size)
121121
122122int UDP::parsePacket ()
123123{
124- // HACK - hand-parse the UDP packet using TCP recv method
125- uint8_t tmpBuf[8 ];
126- int ret =0 ;
127- // read 8 header bytes and get IP and port from it
128- ret = recv (_sock,tmpBuf,8 );
129- if (ret > 0 )
124+ if (available () > 0 )
130125 {
131- _remoteIP = tmpBuf;
132- _remotePort = tmpBuf[4 ];
133- _remotePort = (_remotePort << 8 ) + tmpBuf[5 ];
134- // When we get here, any remaining bytes are the data
135- ret = available ();
126+ // HACK - hand-parse the UDP packet using TCP recv method
127+ uint8_t tmpBuf[8 ];
128+ int ret =0 ;
129+ // read 8 header bytes and get IP and port from it
130+ ret = recv (_sock,tmpBuf,8 );
131+ if (ret > 0 )
132+ {
133+ _remoteIP = tmpBuf;
134+ _remotePort = tmpBuf[4 ];
135+ _remotePort = (_remotePort << 8 ) + tmpBuf[5 ];
136+ // When we get here, any remaining bytes are the data
137+ ret = available ();
138+ }
139+ return ret;
136140 }
137- return ret;
141+ // There aren't any packets available
142+ return 0 ;
138143}
139144
140145int UDP::read ()
You can’t perform that action at this time.
0 commit comments