⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unixsocket.cpp

📁 LINUX下发送邮件的库,测试很好用,有各种发送测试的例子
💻 CPP
字号:
/************************************************************************* *                                                                       * * This program is free software; you can redistribute it and/or modify  * * it under the terms of the GNU General Public License as published by  * * the Free Software Foundation; either version 2 of the License, or     * * (at your option) any later version.                                   * *                                                                       * *************************************************************************/#include "unixsocket.h"/** * Constructor. * * @param argv The program that is to be started, including cmdline *             arguments. */UnixSocket::UnixSocket (const vector<string> &argv) : SSLSocket (argv[0]){	buildArgv (argv);}/** * Constructor. * * @param argv The program that is to be started, including cmdline *             arguments. * @param fd   The file descriptor this socket uses for IO. */UnixSocket::UnixSocket (int fd, const vector<string> &argv) : SSLSocket (argv[0],fd){	buildArgv (argv);}/** * Destructor. */UnixSocket::~UnixSocket (){	int idx = 0;	while (this->argv[idx] != NULL)	{		delete [] this->argv[idx++];	}		delete [] this->argv;}	/** * Open the socket. * * @throws TransferException *                    If the connection to the host cannot be *                    established. */void UnixSocket::connect (){	int fds[2];	if (socketpair (AF_UNIX,SOCK_STREAM,0,fds))	{		throw (TransferException (strerror (errno), "UnixSocket::connect()", 1));	}		switch (fork ()) 	{		case -1:			throw (TransferException (strerror (errno), "UnixSocket::connect()", 2));			break;		case 0:    			/* fds[1] is the parent's end */			close (fds[1]);			if ((dup2 (fds[0],0) == -1) || (dup2 (fds[0],1) == -1))			{				LOG_ERROR << LIBSMTP_I18N_1 ("dup2() failed: ") << strerror (errno) << endl;				exit (1);			}						close (fds[0]);						execvp (this->argv[0], this->argv);						LOG_ERROR << LIBSMTP_I18N_1 ("execvp() failed: ") << strerror (errno) << endl;			exit (0);			break;		default:			/* fds[0] is the child's end */			close (fds[0]);			break;	}		this->sockfd = fds[1];}/** * Build the argv array. * * @param argv The program that is to be started, including cmdline *             arguments. */void UnixSocket::buildArgv (const vector<string> &args){	this->argv = new char*[args.size ()+1];		for (unsigned int idx = 0; idx < args.size (); idx++)	{		int len = args[idx].length ()+1;		this->argv[idx] = new char[len];		strncpy (this->argv[idx], args[idx].c_str (), len);	}	this->argv[args.size ()] = NULL;}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -