资源简介
非常有用的c++代码,可用于Linux和移植到Windows系统,包含用户连接挂载点,caster认证用户,用户发送GGA给caster等
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
ntrip_caster::ntrip_caster()
{
m_listen_sock = 0;
m_epoll_fd = 0;
m_max_count = 0;
m_epoll_events = NULL;
}
ntrip_caster::~ntrip_caster()
{
if(m_listen_sock > 0){
close(m_listen_sock);
}
if(m_epoll_fd > 0){
close(m_epoll_fd);
}
}
bool ntrip_caster::init(int port int sock_count)
{
m_max_count = sock_count;
struct sockaddr_in caster_addr;
memset(&caster_addr 0 sizeof(struct sockaddr_in));
caster_addr.sin_family = AF_INET;
caster_addr.sin_port = htons(port);
caster_addr.sin_addr.s_addr = htonl(INADDR_ANY);
m_listen_sock = socket(AF_INET SOCK_STREAM 0);
if(m_listen_sock == -1) {
exit(1);
}
if(bind(m_listen_sock (struct sockaddr*)&caster_addr sizeof(struct sockaddr)) == -1){
exit(1);
}
if(listen(m_listen_sock 5) == -1){
exit(1);
}
m_epoll_events = new struct epoll_event[sock_count];
if (m_epoll_events == NULL){
exit(1);
}
m_epoll_fd = epoll_create(sock_count);
epoll_ops(m_listen_sock EPOLL_CTL_ADD EPOLLIN);
return true;
}
bool ntrip_caster::init(const char *ip int port int sock_count)
{
m_max_count = sock_count;
struct sockaddr_in server_addr;
memset(&server_addr 0 sizeof(struct sockaddr));
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(port);
server_addr.sin_addr.s_addr = inet_addr(ip);
m_listen_sock = socket(AF_INET SOCK_STREAM 0);
if(m_listen_sock == -1){
exit(1);
}
if(bind(m_listen_sock (struct sockaddr*)&server_addr sizeof(struct sockaddr)) == -1){
exit(1);
}
if(listen(m_listen_sock 5) == -1){
exit(1);
}
m_epoll_events = new struct epoll_event[sock_count];
if (m_epoll_events == NULL){
exit(1);
}
m_epoll_fd = epoll_create(sock_count);
epoll_ops(m_listen_sock EPOLL_CTL_ADD EPOLLIN);
return true;
}
int ntrip_caster::accept_new_client()
{
struct sockaddr_in client_addr;
memset(&client_addr 0 sizeof(struct sockaddr_in));
socklen_t clilen = sizeof(struct sockaddr);
int new_sock = accept(m_listen_sock (struct sockaddr*)&client_addr &clilen);
epoll_ops(new_sock EPOLL_CTL_ADD EPOLLIN);
return new_sock;
}
int ntrip_caster::recv_data(int sock char *recv_buf)
{
char buf[1024] = {0};
int len = 0;
int ret = 0;
while(ret >= 0)
{
ret = recv(sock buf sizeof(buf) 0);
if(ret <= 0)
{
epoll_ops(sock EPOLL_CTL_DEL EPOLLERR);
close(sock);
break;
}else if(ret < 1024){
memcpy(recv_buf buf ret);
len += ret;
break;
}else{
memcpy(recv_buf buf sizeof(buf));
len += ret;
}
}
return ret <= 0 ? ret : len;
}
int ntrip_caster::send_data(int sock const char *send_buf int buf_len)
{
int len = 0;
int ret = 0;
while(len < buf_len){
if(buf_len < 1
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 12533 2019-01-14 11:42 NtripCaster-master\caster\ntrip_caster.cpp
文件 2627 2019-01-18 15:26 NtripCaster-master\client\ntrip_client.cpp
....... 3015 2019-01-14 11:42 NtripCaster-master\include\ntrip_caster.h
....... 841 2019-01-14 11:42 NtripCaster-master\include\ntrip_mountpoint.h
....... 651 2019-01-14 11:42 NtripCaster-master\include\ntrip_util.h
....... 18092 2019-01-14 11:42 NtripCaster-master\LICENSE
....... 930 2019-01-14 11:42 NtripCaster-master\Makefile
....... 295 2019-01-14 11:42 NtripCaster-master\old\Makefile
....... 13115 2019-01-14 11:42 NtripCaster-master\old\ntripcaster.cpp
....... 1349 2019-01-14 11:42 NtripCaster-master\old\ntripcaster.h
....... 1709 2019-01-14 11:42 NtripCaster-master\old\ntripclient.cpp
....... 1571 2019-01-14 11:42 NtripCaster-master\old\ntripserver.cpp
文件 29784 2019-01-14 11:42 NtripCaster-master\old\run\ntripcaster
文件 19240 2019-01-14 11:42 NtripCaster-master\old\run\ntripclient
文件 19496 2019-01-14 11:42 NtripCaster-master\old\run\ntripserver
....... 425 2019-01-14 11:42 NtripCaster-master\old\sourcetable.dat
....... 2328 2019-01-14 11:42 NtripCaster-master\old\util.cpp
....... 742 2019-01-14 11:42 NtripCaster-master\old\util.h
....... 476 2019-01-14 11:42 NtripCaster-master\README
....... 109 2019-01-14 11:42 NtripCaster-master\README.md
文件 39632 2019-01-14 11:42 NtripCaster-master\run\NTRIPCaster
文件 14624 2019-01-14 11:42 NtripCaster-master\run\NTRIPClient
文件 14600 2019-01-14 11:42 NtripCaster-master\run\NTRIPServer
文件 21244 2019-01-18 16:58 NtripCaster-master\server\ntrip_server.cpp
....... 2555 2019-01-14 11:42 NtripCaster-master\util\ntrip_util.cpp
目录 0 2019-01-14 11:42 NtripCaster-master\old\run
目录 0 2019-01-14 11:42 NtripCaster-master\caster
目录 0 2019-01-14 11:42 NtripCaster-master\client
目录 0 2019-01-14 11:42 NtripCaster-master\include
目录 0 2019-01-14 11:42 NtripCaster-master\old
............此处省略7个文件信息
评论
共有 条评论