Commit 9a0d8417 authored by Robert Sprowson's avatar Robert Sprowson Committed by ROOL

Fix for claiming other socket's internet events

Various sloppy management of the socket number meant that NetTime would erroneously claim the internet event for a socket it wasn't using (either before use, or in certain circumstances after use).

In the case observed, socket 0 is opened by a ROM module (DHCP), then NetTime is loaded from disc but not yet attempting a connect (eg. link is down so the state machine idle) the event handler is then higher up the event chain and catching socket 0 events. Subsequent attempts to use DHCP then fail because it never gets the async replies on its socket.

machine.c: Set global sockno to -1 before use. Check the return value of socket() before merrily applying socket options. On closing, set sockno back to -1 via utility function closeconnect().

Version 0.44. Tagged as 'NetTime-0_44'
parent f78f5a68
/* (0.43)
/* (0.44)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 0.43
#define Module_MajorVersion_CMHG 0.44
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 28 Nov 2013
#define Module_Date_CMHG 30 Nov 2019
#define Module_MajorVersion "0.43"
#define Module_Version 43
#define Module_MajorVersion "0.44"
#define Module_Version 44
#define Module_MinorVersion ""
#define Module_Date "28 Nov 2013"
#define Module_Date "30 Nov 2019"
#define Module_ApplicationDate "28-Nov-13"
#define Module_ApplicationDate "30-Nov-19"
#define Module_ComponentName "NetTime"
#define Module_ComponentPath "castle/RiscOS/Sources/Networking/NetTime"
#define Module_FullVersion "0.43"
#define Module_HelpVersion "0.43 (28 Nov 2013)"
#define Module_LibraryVersionInfo "0:43"
#define Module_FullVersion "0.44"
#define Module_HelpVersion "0.44 (30 Nov 2019)"
#define Module_LibraryVersionInfo "0:44"
......@@ -38,7 +38,7 @@
/*
* Public vars
*/
int sockno;
int sockno = -1;
int synchronised;
struct in_addr last_server;
transition_t callback_reason;
......@@ -444,6 +444,11 @@ static int tryconnect(struct sockaddr_in *sa)
/* Make a non-blocking async socket */
sockno = socket(AF_INET, SOCK_DGRAM, 0);
if (sockno == -1)
{
dprintf(("debug", "Failed to make a socket\n"));
return 0;
}
i=1;
socketioctl(sockno, FIONBIO, &i);
socketioctl(sockno, FIOASYNC, &i);
......@@ -455,7 +460,7 @@ static int tryconnect(struct sockaddr_in *sa)
if (connect(sockno, (struct sockaddr*) sa, sizeof *sa) < 0)
{
dprintf(("debug", "Connect error %d\n", errno));
socketclose(sockno);
closeconnect();
return 0;
}
......@@ -479,7 +484,7 @@ static int probe(void)
if (send(sockno, &n, len, 0) < 0)
{
dprintf(("debug", "Send error %d\n", errno));
socketclose(sockno);
closeconnect();
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment