一、初始化的过程

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的初始化和启动的更多相关文章

  1. SuperSocket中的Server是如何初Initialize的

    第一个函数 d:\sourcecode\github\supersocket\quickstart\basic\telnetserver_startbyconfig\program.cs static ...

  2. SuperSocket中的Server是如何初Start的

    第一个函数 d:\sourcecode\github\supersocket\quickstart\basic\telnetserver_startbyconfig\program.cs static ...

  3. Android系统进程间通信(IPC)机制Binder中的Server启动过程源代码分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6629298 在前面一篇文章浅谈Android系 ...

  4. Hadoop源码学习笔记之NameNode启动场景流程四:rpc server初始化及启动

    老规矩,还是分三步走,分别为源码调用分析.伪代码核心梳理.调用关系图解. 一.源码调用分析 根据上篇的梳理,直接从initialize()方法着手.源码如下,部分代码的功能以及说明,已经在注释阐述了. ...

  5. Eclipse中Tomcat Server启动后马上又自动停止报错Address已经使用8005端口 Can't assign requested address (Bind failed)

    Eclipse中Tomcat Server启动后马上又自动停止报错 Can't assign requested address (Bind failed) ,打开Tomcat Server的配置页面 ...

  6. tomcat配置好后,启动eclipse中的server,不能出现有猫的页面,提示404

    原因:tomcat与eclipse中的server未关联起来 解决办法:双击servers中的server,在Server Locations中选中第二项,保存之后再进行刚才的操作就好了.

  7. Solr初始化源码分析-Solr初始化与启动

    用solr做项目已经有一年有余,但都是使用层面,只是利用solr现有机制,修改参数,然后监控调优,从没有对solr进行源码级别的研究.但是,最近手头的一个项目,让我感觉必须把solrn内部原理和扩展机 ...

  8. TaskTracker任务初始化及启动task源码级分析

    在监听器初始化Job.JobTracker相应TaskTracker心跳.调度器分配task源码级分析中我们分析的Tasktracker发送心跳的机制,这一节我们分析TaskTracker接受JobT ...

  9. kube-scheduler源码分析(1)-初始化与启动分析

    kube-scheduler源码分析(1)-初始化与启动分析 kube-scheduler简介 kube-scheduler组件是kubernetes中的核心组件之一,主要负责pod资源对象的调度工作 ...

随机推荐

  1. JMeter怎样测试WebSocket,如何设置(一)

    一.安装WebSocket取样器 1.从JMeter插件管理器官网下载:https://jmeter-plugins.org/ 把这6个jar包放到C:\JMeter\apache-jmeter-3. ...

  2. 梦想CAD控件COM接口标注样式

    增加标注样式 用户可以增加标注样式到数据库,具体实现c#代码如下: private void CreateDim() { //返回控件的数据库对象 MxDrawDatabase database = ...

  3. 数据类型对应字节数(32位,64位 int 占字节数)

    数据类型对应字节数(32位,64位 int 占字节数) 可用如sizeof(char),sizeof(char*)等得出 32位编译器: char :1个字节 char*(即指针变量): 4个字节(3 ...

  4. java string与byte互转

    1.string 转 byte[]byte[] midbytes=isoString.getBytes("UTF8");//为UTF8编码byte[] isoret = srt2. ...

  5. printf函数压栈(i++/i--,++i/--i) 终极解密

    #include <stdio.h> void main() { ; printf("%d %d %d %d\n", i, --i, i, i--); } 输出是“3 ...

  6. [Python3网络爬虫开发实战] 1.1-Python3的安装

    既然要用Python 3开发爬虫,那么第一步一定是安装Python 3.这里会介绍Windows.Linux和Mac三大平台下的安装过程. 1. 相关链接 官方网站:http://python.org ...

  7. subprocess操作命令

    import subprocess 一. run()方法 --->括号里面传参数,主要有cmd, stdout, shell, encoding, check 1.直接传命令 2.命令带参数要以 ...

  8. centOS目录结构介绍

    Linux / CentOS目录结构 /: 根目录,一般根目录下只存放目录,不要存放文件,/etc./bin./dev./lib./sbin应该和根目录放置在一个分区中 /bin:/usr/bin: ...

  9. gitlab root 账号 忘记密码如何重置

    shell>cd /home/git/gitlabshell> su gitshell>bundle exec rails console productionirb(main):0 ...

  10. 10 Python中的代码缓存机制

    目录: 1) 什么是代码块 2) 基本原理 3) 机制适用范围 4) 适用对象 5) 优势 更详细说明,参考太白老师博客 https://www.cnblogs.com/jin-xin/article ...