Some minor changes.

Started to get familiar with the code, again. ;)
Some _very_ small work on Up().


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4305 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Waldemar Kornewald
2003-08-18 11:51:27 +00:00
parent 9495e98e8f
commit aa4dee1bda
5 changed files with 60 additions and 38 deletions
@@ -138,7 +138,10 @@ class PPPInterface {
PPPLCP fLCP;
PPPReportManager fReportManager;
ifnet *fIfnet;
thread_id fUpThread;
uint32 fRetry;
int32 fMaxRetries;
ppp_manager_info *fManager;
@@ -24,13 +24,13 @@ enum PPP_REPORT_TYPE {
// report codes (type-specific)
enum PPP_CONNECTION_REPORT_CODES {
PPP_GOING_UP = 0,
PPP_UP_SUCCESSFUL = 1,
PPP_DOWN_SUCCESSFUL = 2,
PPP_UP_ABORTED = 3,
PPP_UP_FAILED = 4,
PPP_AUTHENTICATION_FAILED = 5,
PPP_CONNECTION_LOST = 6
PPP_REPORT_GOING_UP = 0,
PPP_REPORT_UP_SUCCESSFUL = 1,
PPP_REPORT_DOWN_SUCCESSFUL = 2,
PPP_REPORT_UP_ABORTED = 3,
PPP_REPORT_DEVICE_UP_FAILED = 4,
PPP_REPORT_AUTHENTICATION_FAILED = 5,
PPP_REPORT_CONNECTION_LOST = 6
};
typedef struct ppp_report_packet {
+29 -16
View File
@@ -26,8 +26,9 @@
PPPInterface::PPPInterface(driver_settings *settings, PPPInterface *parent = NULL)
: fSettings(dup_driver_settings(settings)),
fStateMachine(*this), fLCP(*this), fReportManager(StateMachine().Locker()),
fIfnet(NULL), fUpThread(-1), fLinkMTU(1500), fAccessing(0), fChildrenCount(0),
fDevice(NULL), fFirstEncapsulator(NULL), fLock(StateMachine().Locker())
fIfnet(NULL), fUpThread(-1), fRetry(0), fMaxRetries(0), fLinkMTU(1500),
fAccessing(0), fChildrenCount(0), fDevice(NULL), fFirstEncapsulator(NULL),
fLock(StateMachine().Locker())
{
if(get_module(PPP_MANAGER_MODULE_NAME, (module_info**) &fManager) != B_OK)
fManager = NULL;
@@ -46,7 +47,7 @@ PPPInterface::PPPInterface(driver_settings *settings, PPPInterface *parent = NUL
const char *value;
value = get_settings_value(PPP_MODE_KEY, fsettings);
value = get_settings_value(PPP_MODE_KEY, fSettings);
if(!strcasecmp(value, PPP_SERVER_MODE_VALUE))
fMode = PPP_SERVER_MODE;
else
@@ -456,29 +457,41 @@ PPPInterface::Up()
fReportManager.DisableReports(PPP_CONNECTION_REPORT, me);
}
if(report.code == PPP_GOING_UP) {
if(report.code == PPP_REPORT_GOING_UP) {
PPP_REPLY(sender, B_OK);
continue;
} else if(report.code == PPP_UP_SUCCESSFUL) {
} else if(report.code == PPP_REPORT_UP_SUCCESSFUL) {
PPP_REPLY(sender, B_OK);
fReportManager.DisableReports(PPP_CONNECTION_REPORT, me);
return true;
} else if(report.code == PPP_DOWN_SUCCESSFUL
|| report.code == PPP_UP_ABORTED) {
} else if(report.code == PPP_REPORT_DOWN_SUCCESSFUL
|| report.code == PPP_REPORT_UP_ABORTED
|| report.code == PPP_REPORT_AUTHENTICATION_FAILED) {
PPP_REPLY(sender, B_OK);
fReportManager.DisableReports(PPP_CONNECTION_REPORT, me);
return false;
} else if(report.code == PPP_UP_FAILED) {
} else if(report.code == PPP_REPORT_DEVICE_UP_FAILED) {
// TODO:
// if maximum number of retries is reached we return false
// otherwise we wait for the next dial-attempt
} else if(report.code == PPP_AUTHENTICATION_FAILED) {
PPP_REPLY(sender, B_OK);
fReportManager.DisableReports(PPP_CONNECTION_REPORT, me);
return false;
} else if(report.code == PPP_CONNECTION_LOST) {
// !!! check code (after vacation you sometimes forget things ;) !!!
if(fRetry >= fMaxRetries || fUpThread == -1) {
PPP_REPLY(sender, B_OK);
fReportManager.DisableReports(PPP_CONNECTION_REPORT, me);
return false;
} else {
PPP_REPLY(sender, B_OK);
continue;
}
} else if(report.code == PPP_REPORT_CONNECTION_LOST) {
// TODO:
// if autoredial is enabled wait for redial attemts (just continue)
// !!! check code (after vacation you sometimes forget things ;) !!!
if(DoesAutoRedial()) {
PPP_REPLY(sender, B_OK);
continue;
} else {
PPP_REPLY(sender, B_OK);
fReportManager.DisableReports(PPP_CONNECTION_REPORT, me);
return false;
}
}
}
} else {
@@ -318,7 +318,8 @@ PPPStateMachine::UpFailedEvent()
break;
}
Interface()->Report(PPP_CONNECTION_REPORT, PPP_UP_FAILED, NULL, 0);
Interface()->Report(PPP_CONNECTION_REPORT, PPP_REPORT_DEVICE_UP_FAILED,
NULL, 0);
if(Interface()->Parent())
Interface()->Parent()->StateMachine().UpFailedEvent(Interface());
@@ -430,10 +431,10 @@ PPPStateMachine::DownEvent()
|| fAuthenticationStatus == PPP_AUTHENTICATING
|| fPeerAuthenticationStatus == PPP_AUTHENTICATION_FAILED
|| fPeerAuthenticationStatus == PPP_AUTHENTICATING)
Interface()->Report(PPP_CONNECTION_REPORT, PPP_AUTHENTICATION_FAILED,
Interface()->Report(PPP_CONNECTION_REPORT, PPP_REPORT_AUTHENTICATION_FAILED,
NULL, 0);
else
Interface()->Report(PPP_CONNECTION_REPORT, PPP_CONNECTION_LOST,
Interface()->Report(PPP_CONNECTION_REPORT, PPP_REPORT_CONNECTION_LOST,
NULL, 0);
if(Interface()->Parent())
@@ -443,11 +444,14 @@ PPPStateMachine::DownEvent()
if(Interface()->DoesAutoRedial()) {
// TODO:
// Redial()
// redial if we have been connected
// problem: if we are reconfiguring we should redial, too
// if(oldState == PPP_OPENED_STATE)
// Interface()->Redial();
} else if(!Interface()->DoesDialOnDemand())
Interface()->Delete();
} else {
Interface()->Report(PPP_CONNECTION_REPORT, PPP_DOWN_SUCCESSFUL, NULL, 0);
Interface()->Report(PPP_CONNECTION_REPORT, PPP_REPORT_DOWN_SUCCESSFUL, NULL, 0);
if(!Interface()->DoesDialOnDemand())
Interface()->Delete();
@@ -463,7 +467,7 @@ PPPStateMachine::OpenEvent()
switch(State()) {
case PPP_INITIAL_STATE:
if(!Interface()->Report(PPP_CONNECTION_REPORT, PPP_GOING_UP, NULL, 0))
if(!Interface()->Report(PPP_CONNECTION_REPORT, PPP_REPORT_GOING_UP, NULL, 0))
return;
if(Interface()->Mode() == PPP_SERVER_MODE) {
@@ -1378,7 +1382,7 @@ PPPStateMachine::BringHandlersUp()
if(Interface()->Ifnet())
Interface()->Ifnet()->if_flags |= IFF_RUNNING;
Interface()->Report(PPP_CONNECTION_REPORT, PPP_UP_SUCCESSFUL, NULL, 0);
Interface()->Report(PPP_CONNECTION_REPORT, PPP_REPORT_UP_SUCCESSFUL, NULL, 0);
} else
NewPhase(Phase() + 1);
}
+10 -8
View File
@@ -15,11 +15,12 @@ send_data_with_timeout(thread_id thread, int32 code, void *buffer,
for(tries = 0; tries < timeout; tries++) {
if(has_data(thread))
snooze(1000);
else
return send_data(thread, code, buffer, buffer_size);
}
return B_TIMED_OUT;
if(!has_data(thread))
return send_data(thread, code, buffer, buffer_size);
else
return B_TIMED_OUT;
}
@@ -30,14 +31,15 @@ receive_data_with_timeout(thread_id *sender, int32 *code, void *buffer,
int32 tries;
for(tries = 0; tries < timeout; tries++) {
if(has_data(find_thread(NULL))) {
if(!has_data(find_thread(NULL))) {
snooze(1000);
continue;
}
*code = receive_data(sender, buffer, buffer_size);
return B_OK;
}
return B_TIMED_OUT;
if(has_data(find_thread(NULL))) {
*code = receive_data(sender, buffer, buffer_size);
return B_OK;
} else
return B_TIMED_OUT;
}