项目——视频点播系统
项目描述:
用户可以通过浏览器上传视频,并且对自己上传的视频进行管理,而其他用户可以通过浏览器观看视频
开发环境:
Centos7.5、vim、g++、makefile、gdb、git
重要技术:
基于mysql数据库实现视频数据的管理
使用httplib库实现http服务器的搭建
使用jsoncpp实现json格式的序列化与反序列化
使用前端三剑客(html+css+js)实现前端界面模块的优化
项目功能:
采用不太严谨的MVC 框架将项目实现划分为三个模块
数据管理模块:对数据进行同意管理,外界只能通过这个模块访问
前端界面模块:提供前端界面实现与用户的交互
业务处理模块:接收前端请求进行处理,完成用户的需求
项目实现过程
在mysql中执行语句与保存结果集存在线程安全问题
在查询视频信息中,查询语句执行成功了,但是在还没有保存结果集的时候有可能切换到另一个线程,如果另一个线程也在查询表中的信息,这时就会出问题。
执行语句与保存结果集是一个原子操作,要进行加解锁
Httplib搭建http服务器时对对线程的处理流程:
1.首先进来用户先实例化一个srv,创建一张表.
2.填充表中的路由信息,路由信息就是为了告诉srv对象什么请求调用什么函数,设置路由信息之后搭建tcp服务器,收到一个连接之后启动一个线程去处理这个连接;处理的过程就是先接收请求数据,按照http格式进行解析,解析完毕之后得到一个Request请求信息对象,得到请求信息之后然后在路由表中查找针对这个请求方法以及资源路径有没有一个对应的处理函数,如果没有返回404,如果找到了则调用这个函数(根据请求信息进行业务处理,业务处理完毕后给rsp中填充信息,填充完毕后),函数一旦运行完毕后,则会把Reponse中填充的信息组织成为一个http相应数据发送给客户端.
3.这时一个http请求就处理完成了.