origin
steffen 7 years ago
parent 05d86a4456
commit 058d69b97c

@ -0,0 +1,3 @@
2019-01-26:
- TCP::Write - added MSG_NOSIGNAL to send, in case something gets wrong the application would stop working

@ -80,7 +80,7 @@ public:
int Connect();
int Connect(string h, string p);
int Connect(string host, int defaultport);
int Connect(string hostport, int defaultport);
long int ReadPop (char *buffer, long int pktlen, long int bufferlen);
long int ReadTimeout(char *buffer, long int len, int timeout);
long int Read(char *buffer, long int len);
@ -95,6 +95,9 @@ public:
int GetSocket() { return sock; };
void SetSocket(int s, struct sockaddr_storage *saddr, int saddrlen);
const string GetRemoteAddr();
const string GetLocalAddr();
const string WebGetURLHost (string url);
const string WebGetURLPort (string url);
const string WebGetURLFile (string url);

@ -12,6 +12,7 @@
#include <stdlib.h>
#include <string.h> /* memset() */
#include <errno.h>
#include <string.h>
#include "UDPTCPNetwork.h"
@ -231,6 +232,9 @@ long int TCP::ReadTimeout(char *buffer, long int len, int timeout) {
};
//////////////////////////////////////////////////////////
//
// write data, generate no signal if some error occures
long int TCP::Write(char *buffer, long int len) {
int i;
int to = NET_MAX_RETRY;
@ -238,7 +242,7 @@ long int TCP::Write(char *buffer, long int len) {
if (sock <= 0) return -1;
do {
i = send (sock, buffer, len, 0);
i = send (sock, buffer, len, MSG_NOSIGNAL);
} while (i == -1 && (to--) > 0 && errno == EINTR);
if (i < 0) Close ();
@ -399,3 +403,36 @@ const string TCP::WebGetURLFile (string url) {
return result;
};
const string TCP::GetRemoteAddr() {
string ret;
struct sockaddr addr;
socklen_t addrlen = sizeof (struct sockaddr);
char host[256] = "";
char port[256] = "";
if (getpeername (sock, &addr, &addrlen) == -1) {
printf ("getpeername error: %s\n", strerror(errno));
return ret;
}
if (getnameinfo (&addr, addrlen, host, 255, port, 255, 0) == -1) {
printf ("getnameinfo error: %s\n", strerror(errno));
return ret;
}
ret = (string)host + ":" + (string)port;
return ret;
};
const string TCP::GetLocalAddr() {
string ret;
return ret;
};

Loading…
Cancel
Save