Hopefully handle cases when the connection to the server is lost. This should trigger a reconnect.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40748 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -398,7 +398,13 @@ IMAPInboundProtocol::Reconnect()
|
|||||||
bool
|
bool
|
||||||
IMAPInboundProtocol::IsConnected()
|
IMAPInboundProtocol::IsConnected()
|
||||||
{
|
{
|
||||||
return fIsConnected;
|
if (!fIsConnected)
|
||||||
|
return false;
|
||||||
|
if (fIMAPMailbox.IsConnected())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
Disconnect();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ ConnectionReader::_GetNextDataBunch(BString& line, bigtime_t timeout,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int nReaded = fServerConnection->Read(buffer, maxNewLength);
|
int nReaded = fServerConnection->Read(buffer, maxNewLength);
|
||||||
if (nReaded < 0)
|
if (nReaded <= 0)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
fStringBuffer.SetTo(buffer, nReaded);
|
fStringBuffer.SetTo(buffer, nReaded);
|
||||||
@@ -135,7 +135,8 @@ IMAPProtocol::IMAPProtocol()
|
|||||||
fServerConnection(&fOwnServerConnection),
|
fServerConnection(&fOwnServerConnection),
|
||||||
fConnectionReader(fServerConnection),
|
fConnectionReader(fServerConnection),
|
||||||
fCommandId(0),
|
fCommandId(0),
|
||||||
fStopNow(0)
|
fStopNow(0),
|
||||||
|
fIsConnected(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -146,7 +147,8 @@ IMAPProtocol::IMAPProtocol(IMAPProtocol& connection)
|
|||||||
fServerConnection(connection.fServerConnection),
|
fServerConnection(connection.fServerConnection),
|
||||||
fConnectionReader(fServerConnection),
|
fConnectionReader(fServerConnection),
|
||||||
fCommandId(0),
|
fCommandId(0),
|
||||||
fStopNow(0)
|
fStopNow(0),
|
||||||
|
fIsConnected(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -203,6 +205,7 @@ IMAPProtocol::Connect(const char* server, const char* username,
|
|||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
|
fIsConnected = true;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,10 +214,18 @@ status_t
|
|||||||
IMAPProtocol::Disconnect()
|
IMAPProtocol::Disconnect()
|
||||||
{
|
{
|
||||||
ProcessCommand("LOGOUT");
|
ProcessCommand("LOGOUT");
|
||||||
|
fIsConnected = false;
|
||||||
return fOwnServerConnection.Disconnect();
|
return fOwnServerConnection.Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
IMAPProtocol::IsConnected()
|
||||||
|
{
|
||||||
|
return fIsConnected;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ConnectionReader&
|
ConnectionReader&
|
||||||
IMAPProtocol::GetConnectionReader()
|
IMAPProtocol::GetConnectionReader()
|
||||||
{
|
{
|
||||||
@@ -281,8 +292,11 @@ IMAPProtocol::SendCommand(const char* command, int32 commandId)
|
|||||||
|
|
||||||
TRACE("_SendCommand: %s\n", cmd);
|
TRACE("_SendCommand: %s\n", cmd);
|
||||||
int commandLength = strlen(cmd);
|
int commandLength = strlen(cmd);
|
||||||
if (fServerConnection->Write(cmd, commandLength) != commandLength)
|
if (fServerConnection->Write(cmd, commandLength) != commandLength) {
|
||||||
|
// we might lost the connection, clear the connection state
|
||||||
|
Disconnect();
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
fOngoingCommands.push_back(commandId);
|
fOngoingCommands.push_back(commandId);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -301,7 +315,10 @@ IMAPProtocol::HandleResponse(int32 commandId, bigtime_t timeout)
|
|||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
if (status != B_TIMED_OUT)
|
if (status != B_TIMED_OUT)
|
||||||
TRACE("S:read error %s", line.String());
|
TRACE("S:read error %s", line.String());
|
||||||
break;
|
// we might lost the connection, clear the connection state
|
||||||
|
TRACE("Disconnect\n");
|
||||||
|
Disconnect();
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
//TRACE("S: %s", line.String());
|
//TRACE("S: %s", line.String());
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ public:
|
|||||||
const char* username, const char* password,
|
const char* username, const char* password,
|
||||||
bool useSSL = true, int32 port = -1);
|
bool useSSL = true, int32 port = -1);
|
||||||
status_t Disconnect();
|
status_t Disconnect();
|
||||||
|
bool IsConnected();
|
||||||
|
|
||||||
ConnectionReader& GetConnectionReader();
|
ConnectionReader& GetConnectionReader();
|
||||||
status_t SendRawCommand(const char* command);
|
status_t SendRawCommand(const char* command);
|
||||||
@@ -118,6 +119,8 @@ private:
|
|||||||
BString fCommandError;
|
BString fCommandError;
|
||||||
|
|
||||||
vint32 fStopNow;
|
vint32 fStopNow;
|
||||||
|
|
||||||
|
bool fIsConnected;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user