wangyu-UDPspeeder/fd_manager.cpp

80 lines
1.4 KiB
C++
Raw Normal View History

2017-09-25 10:39:05 -05:00
/*
* fd_manager.cpp
*
* Created on: Sep 25, 2017
* Author: root
*/
#include "fd_manager.h"
int fd_manager_t::fd_exist(int fd)
{
return fd_to_fd64_mp.find(fd)!=fd_to_fd64_mp.end();
}
2017-09-26 04:33:48 -05:00
int fd_manager_t::exist(fd64_t fd64)
2017-09-25 10:39:05 -05:00
{
return fd64_to_fd_mp.find(fd64)!=fd64_to_fd_mp.end();
}
2017-09-26 04:33:48 -05:00
/*
2017-09-25 10:39:05 -05:00
fd64_t fd_manager_t::fd_to_fd64(int fd)
{
assert(fd_exist(fd));
return fd_to_fd64_mp[fd];
2017-09-26 04:33:48 -05:00
}*/
int fd_manager_t::to_fd(fd64_t fd64)
2017-09-25 10:39:05 -05:00
{
2017-09-26 04:33:48 -05:00
assert(exist(fd64));
2017-09-25 10:39:05 -05:00
return fd64_to_fd_mp[fd64];
}
2017-09-26 04:33:48 -05:00
/*
2017-09-25 10:39:05 -05:00
void fd_manager_t::remove_fd(int fd)
{
assert(fd_exist(fd));
fd64_t fd64=fd_to_fd64_mp[fd];
fd_to_fd64_mp.erase(fd);
fd64_to_fd_mp.erase(fd64);
//return 0;
2017-09-26 04:33:48 -05:00
}*/
2017-10-08 01:50:48 -05:00
void fd_manager_t::fd64_close(fd64_t fd64)
2017-09-25 10:39:05 -05:00
{
2017-09-26 04:33:48 -05:00
assert(exist(fd64));
2017-09-25 10:39:05 -05:00
int fd=fd64_to_fd_mp[fd64];
fd64_to_fd_mp.erase(fd64);
fd_to_fd64_mp.erase(fd);
2017-09-26 04:33:48 -05:00
if(exist_info(fd64))
{
fd_info_mp.erase(fd64);
}
close(fd);
2017-09-25 10:39:05 -05:00
//return 0;
}
2017-09-27 10:47:32 -05:00
void fd_manager_t::reserve(int n)
2017-09-25 10:39:05 -05:00
{
2017-09-27 10:47:32 -05:00
fd_to_fd64_mp.reserve(n);
fd64_to_fd_mp.reserve(n);
fd_info_mp.reserve(n);
2017-09-25 10:39:05 -05:00
}
2017-09-26 04:33:48 -05:00
u64_t fd_manager_t::create(int fd)
2017-09-25 10:39:05 -05:00
{
assert(!fd_exist(fd));
fd64_t fd64=counter++;
fd_to_fd64_mp[fd]=fd64;
fd64_to_fd_mp[fd64]=fd;
2017-09-26 04:33:48 -05:00
//fd_info_mp[fd64];
2017-09-25 10:39:05 -05:00
return fd64;
}
fd_manager_t::fd_manager_t()
{
counter=u32_t(-1);
2017-09-27 10:47:32 -05:00
counter+=10;
2017-09-25 10:39:05 -05:00
}
2017-09-26 04:33:48 -05:00
fd_info_t & fd_manager_t::get_info(fd64_t fd64)
{
assert(exist(fd64));
return fd_info_mp[fd64];
}
int fd_manager_t::exist_info(fd64_t fd64)
{
return fd_info_mp.find(fd64)!=fd_info_mp.end();
}