当前位置:网站首页>Errno and PERROR
Errno and PERROR
2022-06-30 04:02:00 【I want to master C++】
Linux Error code and its meaning
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <syslog.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
using namespace std;
int bindPort(int nPort)
{
struct sockaddr_in servaddr;
int sockfd, ret;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (-1 == sockfd)
return -1;
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(nPort);
inet_pton(AF_INET, "0.0.0.0", &servaddr.sin_addr);
ret = bind(sockfd, (struct sockaddr *)&servaddr, sizeof(struct sockaddr));
if(0!=ret)
{
perror("Unable to bind socket");
cout << "errno = " << errno << endl;
char*errReason = strerror(errno);
cout << "errReason = " << errReason << endl;
}
close(sockfd);
return ret;
}
bool CheckPortInUse(int nPort)
{
struct sockaddr_in servaddr;
bool ifInUse = false;
int sockfd, ret;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (-1 == sockfd)
return -1;
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(nPort);
inet_pton(AF_INET, "0.0.0.0", &servaddr.sin_addr);
ret = bind(sockfd, (struct sockaddr *)&servaddr, sizeof(struct sockaddr));
if(0!=ret && errno == EADDRINUSE)
{
ifInUse = true;
}
close(sockfd);
return ifInUse;
}
int main()
{
//int ret = CheckPortIsAvailable(6379);
//cout << "ret = " << ret << endl;
bool ifInUse = CheckPortInUse(6379);
if(true == ifInUse)
{
cout << " The port is occupied " << endl;
}
else
{
cout << " The port is not occupied " << endl;
}
}
边栏推荐
- ThingsBoard教程(二三):在规则链中计算二个设备的温度差
- Interface testing -- how to analyze an interface?
- [operation] MySQL query operation 2 on May 25, 2022
- yarn的安装和使用
- Maya Calendar(POJ1008)
- 学校实训要做一个注册页面,要打开数据库把注册页面输入的内容存进数据库但是
- [Thesis reading | deep reading] role2vec:role based graph embeddings
- Unity 在編輯器中輸入字符串時,轉義字符的輸入
- 【云原生】AI云开发平台——AI Model Foundry介绍(开发者可免费体验AI训练模型)
- (Reprinted) an article will take you to understand the reproducing kernel Hilbert space (RKHS) and various spaces
猜你喜欢

About manipulator on Intelligent Vision Group

dotnet-exec 0.5.0 released

Laravel9 installation locale
![[summary of skimming questions] database questions are summarized by knowledge points (continuous update / simple and medium questions have been completed)](/img/89/fc02ce355c99031623175c9f351790.jpg)
[summary of skimming questions] database questions are summarized by knowledge points (continuous update / simple and medium questions have been completed)

MySQL performance optimization (6): read write separation

Solve the problem of Navicat connecting to the database

王爽-汇编语言 万字学习总结

DBT product initial experience

关于智能视觉组上的机械臂

GIS related data
随机推荐
[note] on May 28, 2022, data is obtained from the web page and written into the database
Semantic segmentation resources
DBT product initial experience
. Net 7 JWT configuration is too convenient!
RPC correction
【作业】2022.5.25 MySQL 查操作2
lego_ Reading and summary of loam code
Node-RED系列(二八):基于OPC UA节点与西门子PLC进行通讯
利用反射整合ViewBinding和ViewHolder
【常见问题】浏览器环境、node环境的模块化问题
Radiant energy, irradiance and radiance
(Reprinted) an article will take you to understand the reproducing kernel Hilbert space (RKHS) and various spaces
[note] Introduction to data analysis on June 7, 2022
Version correspondence table of tensorflow, CUDA and bazel
.NET 7 的 JWT 配置太方便了!
第十天 数据的保存与加载
Collinearity problem
Titanic(POJ2361)
(04). Net Maui actual MVVM
【图像融合】基于交叉双边滤波器和加权平均实现多焦点和多光谱图像融合附matlab代码