- WebsocketServer.zip
- src
- WebsocketServer.vcproj
- PushFramework.zip
- WebClient.zip
- css
- ui-lightness
- images
- ui-bg_diagonals-thick_18_b81900_40x40.png
- ui-bg_diagonals-thick_20_666666_40x40.png
- ui-bg_flat_10_000000_40x100.png
- ui-bg_glass_100_f6f6f6_1x400.png
- ui-bg_glass_100_fdf5ce_1x400.png
- ui-bg_glass_65_ffffff_1x400.png
- ui-bg_gloss-wave_35_f6a828_500x100.png
- ui-bg_highlight-soft_100_eeeeee_1x100.png
- ui-bg_highlight-soft_75_ffe45c_1x100.png
- ui-icons_222222_256x240.png
- ui-icons_228ef1_256x240.png
- ui-icons_ef8c08_256x240.png
- ui-icons_ffd27a_256x240.png
- ui-icons_ffffff_256x240.png
- jquery-ui-1.8.18.custom.css
- js
- websocket_client.css
- websocket_client.html
- WebsocketProtocol.zip
- base64
- WebsocketProtocol.vcproj
- AllInOne.zip
- PushFramework
- WebClient
- css
- ui-lightness
- images
- ui-bg_diagonals-thick_18_b81900_40x40.png
- ui-bg_diagonals-thick_20_666666_40x40.png
- ui-bg_flat_10_000000_40x100.png
- ui-bg_glass_100_f6f6f6_1x400.png
- ui-bg_glass_100_fdf5ce_1x400.png
- ui-bg_glass_65_ffffff_1x400.png
- ui-bg_gloss-wave_35_f6a828_500x100.png
- ui-bg_highlight-soft_100_eeeeee_1x100.png
- ui-bg_highlight-soft_75_ffe45c_1x100.png
- ui-icons_222222_256x240.png
- ui-icons_228ef1_256x240.png
- ui-icons_ef8c08_256x240.png
- ui-icons_ffd27a_256x240.png
- ui-icons_ffffff_256x240.png
- jquery-ui-1.8.18.custom.css
- js
- websocket_client.css
- websocket_client.html
- Websocket Server
- WebsocketProtocol
- src
- WebsocketProtocol.vcproj
- WebsocketProtocol.vcproj.ahmed-PC.ahmed.user
- WebsocketServer
- src
- WebsocketServer.vcproj
- WebsocketServer.vcproj.ahmed-PC.ahmed.user
- Websocket.sln
- allinone.zip
|
/********************************************************************
File : ClientFactoryImpl.cpp
Creation date : 2010/6/27
License : Copyright 2010 Ahmed Charfeddine, http://www.pushframework.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*********************************************************************/
#include "StdAfx.h"
#include "ClientFactoryImpl.h"
#include "../include/LogicalConnection.h"
#include "../include/ClientFactory.h"
#include "PhysicalConnection.h"
#include "ServerImpl.h"
#include "ServerStats.h"
#include "../include/BroadcastManager.h"
#include "BroadcastManagerImpl.h"
#include "Dispatcher.h"
#include "GarbageCollector.h"
#include "ScopedLock.h"
namespace PushFramework
{
PUSHFRAMEWORK_API void ReturnClient(LogicalConnection* pClient)
{
clientFactoryImpl.ReturnClient(pClient);
}
PUSHFRAMEWORK_API LogicalConnection* FindClient(CLIENT_KEY clientName)
{
return clientFactoryImpl.FindLogicalConnection(clientName);
}
PUSHFRAMEWORK_API void Disconnect( LogicalConnection* pLogicalConnection, bool waitForPendingPackets )
{
clientFactoryImpl.Disconnect(pLogicalConnection, waitForPendingPackets, false);
}
PUSHFRAMEWORK_API void DisconnectAndReturn( LogicalConnection* pLogicalConnection, bool waitForPendingPackets )
{
clientFactoryImpl.Disconnect(pLogicalConnection, waitForPendingPackets, true);
}
ClientFactoryImpl clientFactoryImpl;
ClientFactoryImpl::ClientFactoryImpl()
{
nClientsCount = 0;
::InitializeCriticalSection(&cs);
}
ClientFactoryImpl::~ClientFactoryImpl(void)
{
::DeleteCriticalSection(&cs);
}
LogicalConnection* ClientFactoryImpl::AddLogicalConnection( LogicalConnection* pClient )
{
std::string key(pClient->getKey());
ScopedLock csLock(cs);
//
LogicalConnection* pRet = pClient;
clientMapT::iterator it = clientMap.find(key);
if(it!=clientMap.end())
{
pRet = it->second;
}
else
{
clientMap[key] = pClient;
nClientsCount++;
}
pRet->IncrementUsage();
return pRet;
}
LogicalConnection* ClientFactoryImpl::FindLogicalConnection( const char* _key )
{
std::string key(_key);
//
ScopedLock csLock(cs);
clientMapT::iterator it = clientMap.find(key);
if(it==clientMap.end())
return NULL;
LogicalConnection* pClient = it->second;
pClient->IncrementUsage();
return pClient;
}
Server* ClientFactoryImpl::getServer()
{
return pServerImpl->getFacade();
}
void ClientFactoryImpl::SilentDisconnect( LogicalConnection* pLogicalConnection )
{
if (!RemoveIfExisting(pLogicalConnection))
{
return;
}
pLogicalConnection->pPhysicalConnection->Close(false);
//Send to garbage collector.
garbageCollector.AddDisposableClient(pLogicalConnection);
}
void ClientFactoryImpl::Disconnect( LogicalConnection* pLogicalConnection, bool waitForPendingPackets , bool returnClient)
{
if (!RemoveIfExisting(pLogicalConnection))
{
if (returnClient)
{
pLogicalConnection->DecrementUsage();
}
return;
}
pLogicalConnection->pPhysicalConnection->Close(waitForPendingPackets);
//Now it is set to disconnected.
pServerImpl->getClientFactory()->onBeforeDisposeClient(pLogicalConnection);
broadcastManagerImpl.RemoveClient(pLogicalConnection->getKey());
dispatcher.NotifyObserversClientOut(pLogicalConnection->getKey());
//Statistics :
stats.addToCumul(ServerStats::VisitorsHitsOut, 1);
stats.addToCumul(ServerStats::VisitorsOnline, -1);
stats.addToDuration(ServerStats::VisitorsDuration, pLogicalConnection->getVisitDuration());
if (returnClient)
{
pLogicalConnection->DecrementUsage();
}
//Send to garbage collector.
garbageCollector.AddDisposableClient(pLogicalConnection);
}
bool ClientFactoryImpl::RemoveIfExisting( LogicalConnection* pLogicalConnection )
{
ScopedLock csLock(cs);
clientMapT::iterator it = clientMap.find(pLogicalConnection->getKey());
if (it == clientMap.end())
{
return false;
}
nClientsCount--;
clientMap.erase(it);
return true;
}
unsigned int ClientFactoryImpl::GetClientCount()
{
return nClientsCount;
}
void ClientFactoryImpl::ReturnClient( LogicalConnection* pClient )
{
pClient->DecrementUsage();
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.