SuperSocket中的Server的初始化和启动
一、初始化的过程
static void Main(string[] args)
{
var bootstrap = BootstrapFactory.CreateBootstrap(); if (!bootstrap.Initialize())
{
Console.WriteLine("Failed to initialize!");
Console.ReadKey();
return;
}
}
supersocket\socketengine\defaultbootstrap.cs
DefaultBootStrap.cs
public virtual bool Initialize()
{
return Initialize(c => c);
} public virtual bool Initialize(Func<IServerConfig, IServerConfig> serverConfigResolver)
{
return Initialize(serverConfigResolver, null);
} public virtual bool Initialize(Func<IServerConfig, IServerConfig> serverConfigResolver, ILogFactory logFactory)
{
foreach (var factoryInfo in workItemFactories)
{
IWorkItem appServer = InitializeAndSetupWorkItem(factoryInfo);
}
} private IWorkItem InitializeAndSetupWorkItem(WorkItemFactoryInfo factoryInfo)
{
setupResult = SetupWorkItemInstance(appServer, factoryInfo); } internal virtual bool SetupWorkItemInstance(IWorkItem workItem, WorkItemFactoryInfo factoryInfo)
{
return workItem.Setup(this, factoryInfo.Config, factoryInfo.ProviderFactories.ToArray());
}
supersocket\socketbase\appserverbase.cs
bool IWorkItem.Setup(IBootstrap bootstrap, IServerConfig config, ProviderFactoryInfo[] factories)
{
Bootstrap = bootstrap;
if (!SetupFinal())
return false; } private bool SetupFinal()
{
return SetupSocketServer();
} private bool SetupSocketServer()
{
m_SocketServer = m_SocketServerFactory.CreateSocketServer<TRequestInfo>(this, m_Listeners, Config);
}
supersocket\socketengine\socketserverfactory.cs
public ISocketServer CreateSocketServer<TRequestInfo>(IAppServer appServer, ListenerInfo[] listeners, IServerConfig config)
where TRequestInfo : IRequestInfo
{
case(SocketMode.Tcp):
return new AsyncSocketServer(appServer, listeners);
}
二、启动的过程
var bootstrap = BootstrapFactory.CreateBootstrap();
var result = bootstrap.Start();
supersocket\socketengine\defaultbootstrap.cs
//Initialize servers
foreach (var factoryInfo in workItemFactories)
{
IWorkItem appServer = InitializeAndSetupWorkItem(factoryInfo);
if (appServer == null)
return false;
if (factoryInfo.IsServerManager)
serverManager = appServer;
else if (!(appServer is IsolationAppServer))//No isolation
{
//In isolation mode, cannot check whether is server manager in the factory info loader
if (TypeValidator.IsServerManagerType(appServer.GetType()))
serverManager = appServer;
}
m_AppServers.Add(appServer);
}
public StartResult Start()
{
foreach (var server in m_AppServers)
{
if (!server.Start())
{}
}
}
supersocket\socketbase\appserver.cs
public override bool Start()
{
if (!base.Start())
return false;
}
supersocket\socketbase\appserverbase.cs
m_SocketServer = m_SocketServerFactory.CreateSocketServer<TRequestInfo>(this, m_Listeners, Config);
public virtual bool Start()
{
if (!m_SocketServer.Start())
{
m_StateCode = ServerStateConst.NotStarted;
return false;
}
}
SuperSocket\SocketEngine\AsyncSocketServer.cs
public override bool Start()
{
if (!base.Start())
return false;
}
supersocket\socketengine\socketserverbase.cs
var listener = CreateListener(ListenerInfos[i]);
d:\sourcecode\github\supersocket\socketengine\tcpsocketserverbase.cs
protected override ISocketListener CreateListener(ListenerInfo listenerInfo)
{
return new TcpAsyncSocketListener(listenerInfo);
}
d:\sourcecode\github\supersocket\socketengine\tcpasyncsocketlistener.cs
public TcpAsyncSocketListener(ListenerInfo info)
: base(info)
{
m_ListenBackLog = info.BackLog;
}
d:\sourcecode\github\supersocket\socketengine\socketlistenerbase.cs
protected SocketListenerBase(ListenerInfo info)
{
Info = info;
}
public SocketServerBase(IAppServer appServer, ListenerInfo[] listeners)
{
AppServer = appServer;
IsRunning = false;
ListenerInfos = listeners;
Listeners = new List<ISocketListener>(listeners.Length);
}
public TcpSocketServerBase(IAppServer appServer, ListenerInfo[] listeners)
: base(appServer, listeners)
public virtual bool Start()
{
if (listener.Start(AppServer.Config))
{
}
}
SuperSocket\SocketEngine\TcpAsyncSocketListener.cs
d:\sourcecode\github\supersocket\socketengine\socketlistenerbase.cs
public ListenerInfo Info { get; private set; }
protected SocketListenerBase(ListenerInfo info)
{
Info = info;
}
public override bool Start(IServerConfig config)
{
m_ListenSocket = new Socket(this.Info.EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
if (!m_ListenSocket.AcceptAsync(acceptEventArg))
ProcessAccept(acceptEventArg);
}
SuperSocket中的Server的初始化和启动的更多相关文章
- SuperSocket中的Server是如何初Initialize的
第一个函数 d:\sourcecode\github\supersocket\quickstart\basic\telnetserver_startbyconfig\program.cs static ...
- SuperSocket中的Server是如何初Start的
第一个函数 d:\sourcecode\github\supersocket\quickstart\basic\telnetserver_startbyconfig\program.cs static ...
- Android系统进程间通信(IPC)机制Binder中的Server启动过程源代码分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6629298 在前面一篇文章浅谈Android系 ...
- Hadoop源码学习笔记之NameNode启动场景流程四:rpc server初始化及启动
老规矩,还是分三步走,分别为源码调用分析.伪代码核心梳理.调用关系图解. 一.源码调用分析 根据上篇的梳理,直接从initialize()方法着手.源码如下,部分代码的功能以及说明,已经在注释阐述了. ...
- Eclipse中Tomcat Server启动后马上又自动停止报错Address已经使用8005端口 Can't assign requested address (Bind failed)
Eclipse中Tomcat Server启动后马上又自动停止报错 Can't assign requested address (Bind failed) ,打开Tomcat Server的配置页面 ...
- tomcat配置好后,启动eclipse中的server,不能出现有猫的页面,提示404
原因:tomcat与eclipse中的server未关联起来 解决办法:双击servers中的server,在Server Locations中选中第二项,保存之后再进行刚才的操作就好了.
- Solr初始化源码分析-Solr初始化与启动
用solr做项目已经有一年有余,但都是使用层面,只是利用solr现有机制,修改参数,然后监控调优,从没有对solr进行源码级别的研究.但是,最近手头的一个项目,让我感觉必须把solrn内部原理和扩展机 ...
- TaskTracker任务初始化及启动task源码级分析
在监听器初始化Job.JobTracker相应TaskTracker心跳.调度器分配task源码级分析中我们分析的Tasktracker发送心跳的机制,这一节我们分析TaskTracker接受JobT ...
- kube-scheduler源码分析(1)-初始化与启动分析
kube-scheduler源码分析(1)-初始化与启动分析 kube-scheduler简介 kube-scheduler组件是kubernetes中的核心组件之一,主要负责pod资源对象的调度工作 ...
随机推荐
- js获取微信版本号的方法
微信现在几乎已经普遍在使用,但是微信版本一直在更新,不同的版本有不同的功能,于是了解微信的版本号很重要,以便自己及时更新体验新的功能.那么如何用js获取微信版本号呢? 一.判断微信版本号 ? 1 2 ...
- HFS模板开发
痉挛模板, 节, 符号 & 变量帮助需要更多帮助 吗?看看 下面这些链接-模板是模型痉挛用于构建 HTML 页面. -它分为几个部分, 每个部分描述最终 HTML 页面的一部分. -此模板必须 ...
- CAD把控件图形变成二进制流输出(com接口VB语言)
主要用到函数说明: _DMxDrawX::WriteBinStream 把控件图形变成二进制流输出,详细说明如下: 参数 说明 VARIANT* pVarBinArray 输出二进制数组.是个byte ...
- Java实现打包文件
把文件打包到压缩包里 public void zip (String... files) throws IOException { //创建文件打包流对象 ZipOutputStream zos = ...
- python bs4库
Beautiful Soup parses anything you give it, and does the tree traversal stuff for you. BeautifulSoup ...
- valgrind检查代码内存泄漏,5种内存泄漏情况
摘要: valgrind是linux下用于调试程序和查找内存泄露的常用工具.valgrind会报告5种内存泄露,"definitely lost", "indirectl ...
- 诊断:记一次存储异常CRASH致数据库无法正常打开的恢复
数据库存储异常crash,首先控制文件出现问题 ORA-: ????? ???? ORA-: ???? : '/oracledata/oradata/orc11rac/orc11rac/system0 ...
- P1036 选数(DFS)
题目 https://www.luogu.org/problemnew/show/P1036 思路 搜索,使用递归实现dfs,所有数字遍历一遍,当取遍所有数组的index(扫了一遍,并非一定是选取了) ...
- <MySQL>入门四 事务控制语言 TCL
-- TCL /* Transcation Control Language 事务控制语言 事务:一个或一组sql语句组成一个执行单元,这个执行单元要么全部执行,要么全部不执行 案例:转账 name ...
- Mac 当xampp里mysql无法启动的解决办法
sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start