socket_len udp_socket::send(net_comm_data& __senddata) { if (!check_socket_ok()) { LOG_OUT("send socket is a invalid socket!\n", 0); return -1; } int send_result = ::sendto (m_socket, __senddata.get_buffer(), __senddata.active_size(), __senddata.m_flag, &(__senddata.m_target_ip_addr.m_socket_info.m_ipaddr), (__senddata.m_target_ip_addr.m_socket_size)); if (SOCKET_ERROR == send_result) { LOG_OUT("sendto error,return =%d, wsa error code = %d\n", send_result, net_system_t::get_last_error()); } else { LOG_OUT ("send size = %d\n", send_result); } return send_result; }
static int _create_pid_file(void) { int ret = ERROR; FILE* pidfile; /* Check whether this process is running */ if ((pidfile = fopen(PID_FILE_PATH, "r"))) { LOG_OUT("sheduled has been started"); fclose(pidfile); return ERROR; } /* Create pid file */ if ((pidfile = fopen(PID_FILE_PATH, "w"))) { fprintf(pidfile, "%d\n", getpid()); fclose(pidfile); ret = OK; } else { perror("pidfile"); ret = ERROR; } return ret; }
static void _close(int signo) { LOG_OUT("recvd SIGTERM, exit now."); _log_to_file(LOG_FILE_PATH, "recvd SIGTERM, exit now!"); unlink(PID_FILE_PATH); exit(0); }
bool CVideoPlayer::LoadDBFile( int eImageOrVideo, string strPathOrFileName ) { bool retVal = true; if(m_objDBSeq == NULL) { retVal = false; m_eDBmode = eImageOrVideo; switch(eImageOrVideo) { case DB_IMAGE: m_objDBSeq = new CImgSeq(); break; case DB_VIDEO: m_objDBSeq = new CVideoSeq(); break; default: m_eDBmode = DB_UNDEFINED; LOG_OUT("Argument [eImageOrVideo] can be DB_IMAGE or DB_VIDEO...\n"); break; } if(m_objDBSeq) { if(!m_objDBSeq->LoadDB(strPathOrFileName)) { UnloadDBFile(); retVal = false; } else { m_nCurrFrame = 0; m_nTotalFrame = m_objDBSeq->GetTotalFrame(); m_strPathAbsolute = m_objDBSeq->GetPathAbsolute(); m_sizeFrame = m_objDBSeq->GetFrameSize(); retVal = true; } } } else { LOG_OUT("Run UnloadDBFile() first...\n"); } return retVal; }
socket_len udp_socket::recv(net_comm_data& _recvdata) { if (!check_socket_ok()) { LOG_OUT("recv socket is a invalid socket!\n", 0); return -1; } int addr_family = m_local_ip.m_socket_info.m_addr_family; switch (addr_family) { case AF_INET: _recvdata.m_target_ip_addr.m_socket_size = sizeof (sockaddr_in); break; case AF_INET6: _recvdata.m_target_ip_addr.m_socket_size = sizeof (sockaddr_in6); break; default: _recvdata.m_target_ip_addr.m_socket_size = sizeof (sockaddr); break; } int recv_result = ::recvfrom(m_socket, _recvdata.get_buffer(), _recvdata.buffer_size(), _recvdata.m_flag, &(_recvdata.m_target_ip_addr.m_socket_info.m_ipaddr), &(_recvdata.m_target_ip_addr.m_socket_size)); if (SOCKET_ERROR == recv_result) { LOG_OUT("recvfrom error,return =%d, wsa error code = %d\n", recv_result, net_system_t::get_last_error()); } else { LOG_OUT ("recv size = %d\n", recv_result); } return recv_result; }
bool CVideoPlayer::GoToSpecificFrame( int nSpecFrame ) { if(nSpecFrame < 0 || nSpecFrame >= m_nTotalFrame) { char szErr[100]; sprintf_s(szErr, "frame is out-of-range : it should be 0-%d..\n",m_nTotalFrame-1); LOG_OUT(szErr); return false; } m_nCurrFrame = nSpecFrame; return true; }
//@override bool CAdvancedAnnotator::GoToSpecificFrame( int nSpecFrame ) { if(m_nCurrFrame != nSpecFrame) { SyncXmlFrameInfo(); m_pXMLDoc->SaveFile((m_strPathAbsolute+m_strXMLFileName).c_str()); } if(nSpecFrame < 0 || nSpecFrame >= m_nTotalFrame) { char szErr[100]; sprintf_s(szErr, "frame is out-of-range : it should be 0~%d..\n",m_nTotalFrame-1); LOG_OUT(szErr); return false; } LoadFrame(nSpecFrame); return true; }
int udp_socket::init(ip_addr_info_t& local_ip_info, bool bEnable_auto_bind, // = true bool enable_bind //= true ) { if (check_socket_ok()) { close(); } int status = PFX_STATUS_OK; FOR_ONE_LOOP_BEGIN m_socket = ::socket(local_ip_info.m_socket_info.m_addr_family, SOCK_DGRAM, IPPROTO_UDP); if (!check_socket_ok()) { LOG_OUT("WSASocket error,error code = %d", net_system_t::get_last_error()); status = PFX_STATUS_FAIL; break; } if (enable_bind) { int bind_result = SOCKET_ERROR; if (bEnable_auto_bind) { unsigned short backup_port = htons(local_ip_info.m_socket_info.m_ipv4addr.sin_port); for (unsigned short try_port = backup_port; try_port<65535; ++try_port) { local_ip_info.m_socket_info.m_ipv4addr.sin_port = htons(try_port); bind_result = bind (m_socket, &local_ip_info.m_socket_info.m_ipaddr, local_ip_info.m_socket_size); if (SOCKET_ERROR != bind_result) { LOG_OUT ("绑定端口为:%d\n", try_port); break; } } if (SOCKET_ERROR == bind_result) { LOG_OUT("port %d ~ 65535 bind error,error code = %d", backup_port, GetNetLastErrorCode()); local_ip_info.m_socket_info.m_ipv4addr.sin_port = htons(backup_port); close(); status = PFX_STATUS_FAIL; break; } } else { bind_result = bind (m_socket, &local_ip_info.m_socket_info.m_ipaddr, local_ip_info.m_socket_size); if (SOCKET_ERROR != bind_result) { LOG_OUT ("绑定端口为:%d\n", htons(local_ip_info.m_socket_info.m_ipv4addr.sin_port)); break; } else { LOG_OUT("bind error,error code = %d",net_system_t::get_last_error()); close(); status = PFX_STATUS_FAIL; break; } } } m_local_ip = local_ip_info; FOR_ONE_LOOP_END return status; }