CentOS 7.3 修复NetwrokManager的bug

在最开始使用CentOS Linux release 7.0的时候。就发现重启网卡会导致firewalld配置失效。
也曾在知乎上提问过 CentOS 7.2.1511 (Core) 上配置firewalld的zone绑定?
在最新版本的CentOS 7.3.1611下

[21:23:14 ~]# NetworkManager --version
1.4.0-14.el7_3

NetworkManager修复了该问题.
在/etc/sysconfig/network-scripts/ifcfg-X配置文件中加入ZONE参数,NetworkManager就配置网卡到firewalld的对应zone上.

Proxy Auto Config

前不久和机房交涉,提到有需求访问google,和一些国外站点,便于查找资料。
机房很慷慨的提供了一条香港专线,提供给我们翻墙。(不要太贴心)
于是就用一台负载不大的服务器配置上专线IP。然后搭建个pptpd,使用策略路由(ip rule from),让拨号的流量全发给专线的网关。
很欢乐的用电脑拨号,没问题。然后用手机,卧槽,ios系统已经弃用了pptp协议的vpn传输。
没办法。重新用xl2tpd再搭建一个。+_+
通过l2tp/ipsec类型VPN拨号,相当于把所有流量转发给VPN服务器,服务器再通过策略路由,把流量转发给香港的IP,达到翻墙的效果。
但是这种vpn拨号的方式,局限性很大。
所有在使用的软件都会离线,只有局域内网可以直接访问,其他所有请求都会走国外线路(专线)。
在需要访问google的时候还要专门去设置一下VPN拨号,不需要了,还需要断开。
太特么麻烦了。每天让我QQ,网易云音乐,上上下下几十次。(一秒几十万上下好么,=_=)
于是决定使用代理的方式翻墙,用PAC脚本来设置那些网站可以使用代理(这样也可以防止某些喜欢看国外视频直播的带宽终结者)。
于是先找些PAC脚本资料(wiki),然后自己写了一个。(点这里查看
但是在技术部署上遇到一个问题,在使用squid做代理时,他会通过默认网关发送请求。
在折腾了一天后,在官方的文档中找到了tcp_outgoing_address这个配置参数,于是很简单的再使用策略路由,使squid流量走专线。(squid官方文档
然后配置下windows的代理,很方便的就可以翻墙了,而且本地网络不受影响。

C++ 练习

今天下午看书的时候发现一个很有趣的问题。
《C++ Primer Plus》
示例14.1(studentc.h)中,定义了两个非常奇怪的类成员函数

#ifndef STUDENTC_H_
#define STUDENTC_H_

#include <iostream>
#include <string>
#include <valarray>

class Student
{
private:
        typedef std::valarray<double> ArrayDb;
        std::string name;
        ArrayDb scores;
        std::ostream & arr_out(std::ostream & os) const;
public:
        Student() :name("Null Student"), scores() {}
        explicit Student(const std::string & s) :name(s), scores() {}
        explicit Student(int n) :name("Nully"), scores(n) {}
        Student(const std::string & s, int n) :name(s), scores(n) {}
        Student(const std::string & s, const ArrayDb & a) : name(s), scores(a) {}
        Student(const char * str, const double * pd, int n) :name(str), scores(pd,n) {}
        ~Student() {}
        double Average() const;
        const std::string & Name() const;
//[]重载函数1,似乎能匹配所有的调用
        double & operator[](int i);
//[]重载函数2,在有上面的重载函数下,似乎永远匹配不到
        double operator[](int i) const;

        friend std::istream & operator>>(std::istream & is, Student & stu);
        friend std::istream & getline(std::istream & is, Student & stu);
        friend std::ostream & operator<<(std::ostream & os,const Student & stu);
};

#endif

在实现中分别添加两个重载函数的输出,查看调用的情况

#include "studentc.h"
using std::ostream;
using std::endl;
using std::istream;
using std::string;

double Student::Average() const
{
	if (scores.size() > 0)
		return scores.sum() / scores.size();
	else
		return 0;
}

const string & Student::Name() const
{
	return name;
}

double & Student::operator[](int i)
{
	std::cout << "Use double & " << std::endl;
	return scores[i];
}

double Student::operator[](int i) const
{
	std::cout << "Use double " << std::endl;
	return scores[i];
}

ostream & Student::arr_out(ostream & os) const
{
	int i;
	int lim = scores.size();
	if (lim > 0)
	{
		for(i = 0; i < lim; i++)
		{
			os << scores[i] << " ";
			if ( i % 5 == 4)
				os << endl;
		}
		if ( i % 5 != 0)
			os << endl;
	}
	else
		os << " empty array ";
	return os;
}

istream & operator>>(istream & is, Student & stu)
{
	is >> stu.name;
	return is;
}

istream & getline(istream & is, Student & stu)
{
	getline(is,stu.name);
	return is;
}

ostream & operator<<(ostream & os, const Student & stu)
{
	os << "Scores for " << stu.name << ":\n";
	stu.arr_out(os);
	return os;
}
#include "studentc.h"
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

void set(Student & sa, int n);
const int pupils = 3;
const int quizzes = 5;

int main(void)
{
	Student ada[pupils] = { Student(quizzes), Student(quizzes), Student(quizzes) };
	int i;
	for (i = 0; i < pupils; ++i)
		set(ada[i], quizzes);
	cout << "\nStudent List:\n";
	for (i = 0; i < pupils; ++i)
		cout << ada[i].Name() << endl;
	cout << "\nResults:";
	for (i = 0; i < pupils; ++i)
	{
		cout << endl << ada[i];
		cout << "average: " << ada[i].Average() << endl;
	}
	cout << "Done.\n";
	return 0;
}

void set(Student & sa, int n)
{
	cout << "Please enter the student's name: ";
	getline(cin,sa);
	cout << "Please enter " << n << " quiz scores:\n";
	for (int i = 0; i < n; i++)
		cin >> sa[i];
	while (cin.get() != '\n')
		continue;
}
[code title="输出结果"]
Please enter the student's name: Gil Bayts
Please enter 5 quiz scores:
Use double & 
92 94 96 93 95
Use double & 
Use double & 
Use double & 
Use double & 
Please enter the student's name: Pat Roone
Please enter 5 quiz scores:
Use double & 
83 89 72 78 95
Use double & 
Use double & 
Use double & 
Use double & 
Please enter the student's name: Fleur O'Day
Please enter 5 quiz scores:
Use double & 
92 89 96 74 64
Use double & 
Use double & 
Use double & 
Use double & 

Student List:
Gil Bayts
Pat Roone
Fleur O'Day

Results:
Scores for Gil Bayts:
92 94 96 93 95 
average: 94

Scores for Pat Roone:
83 89 72 78 95 
average: 83.4

Scores for Fleur O'Day:
92 89 96 74 64 
average: 83
Done.

可以看到,const版本的operator[]完全没有匹配到。