当前位置:网站首页>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;
}
}
边栏推荐
- 【笔记】2022.5.27 通过pycharm操作MySQL
- [punch in - Blue Bridge Cup] day 1 --% 7F format output
- [fuzzy neural network prediction] water quality prediction based on fuzzy neural network, including Matlab source code
- Is the largest layoff and salary cut on the internet coming?
- Practical debugging skills
- [image fusion] multi focus and multi spectral image fusion based on cross bilateral filter and weighted average with matlab code
- 11: I came out at 11:04 after the interview. What I asked was really too
- How to analyze and solve the problem of easycvr kernel port error through process startup?
- (03). Net Maui actual combat basic control
- Graduation project EMS office management system (b/s structure) +j2ee+sqlserver8.0
猜你喜欢

MySQL performance optimization (6): read write separation
![[note] May 23, 2022 MySQL](/img/a1/dd71610236729e1d25c4c3e903c0e0.png)
[note] May 23, 2022 MySQL

11: I came out at 11:04 after the interview. What I asked was really too
![[fuzzy neural network prediction] water quality prediction based on fuzzy neural network, including Matlab source code](/img/88/038826ec6d16c8eb04d9ef2e01d47a.png)
[fuzzy neural network prediction] water quality prediction based on fuzzy neural network, including Matlab source code

Sql语句遇到的错误,求解

【论文阅读|深读】Role2Vec:Role-Based Graph Embeddings

Interface testing -- how to analyze an interface?

MySQL performance optimization (5): principle and implementation of master-slave synchronization

Huawei cloud native - data development and datafactory

绿色新动力,算力“零”负担——JASMINER X4系列火爆热销中
随机推荐
Pig-Latin (UVA492)
【笔记】2022.5.28 从网页获取数据并写入数据库
How to analyze and solve the problem of easycvr kernel port error through process startup?
Litjson parses the generated JSON file and reads the dictionary in the JSON file
How to use Jersey to get the complete rest request body- How to get full REST request body using Jersey?
接口测试--如何分析一个接口?
Laravel9 installation locale
Cloud native -- websocket of Web real-time communication technology
[personal summary] learning plan
Is the largest layoff and salary cut on the internet coming?
Interpretation score of bilstm-crf in NER_ sentence
Half a year after joining the company, I was promoted to a management post
【模糊神经网络预测】基于模糊神经网络实现水质预测含Matlab源码
(03). Net Maui actual combat basic control
Huawei cloud native - data development and datafactory
基于海康EhomeDemo工具排查公网部署出现的视频播放异常问题
[punch in - Blue Bridge Cup] day 1 --% 7F format output
How to view Tencent's 2022 school recruitment salary, the total contract of cabbage is 40W?
[punch in - Blue Bridge Cup] day 3 --- slice in reverse order list[: -1]
[note] Introduction to data analysis on June 7, 2022