原创 文件鎖

1. sample學習代碼 #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <string.h> #inclu

原创 非阻塞io和IO多路轉接

本文參考《Unix高級環境編程》,僅用於個人學習,備忘。 1. sample 學習代碼 #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd

原创 linux路由服務

本文介紹如何使用linux創建一臺簡單的路由服務器。主要包括幾個參數的設置:ip_forward和rp_filter。1.開啓IP forwarding # 重啓後失效 $ echo "1" > /proc/sys/net/ipv4/i

原创 socket編程:backlog值對listen連接狀態的影響

1. 概述 對於TCP服務器,使用bind綁定一個地址和端口,然後使用listen(backlog)在這個socket上監聽用戶的連接請求。其中,backlog參數的大小,決定了TCP服務器的連接請求隊列大小,進一步影響客戶端連接請求的成

原创 python處理中文字符

1.在py文件中使用中文字符 unicode.py文件內容如下所示: # -*- coding:utf-8 -*- str_ch = '我們women' uni_ch = u'我們women' print "type:", type

原创 ElementTree處理xml

1. 示例用法 參照官方文檔,創建country_data.xml測試文檔,內容如下: <?xml version="1.0"?> <data> <country name="Liechtenstein"> <ra

原创 XML基礎知識

大部分內容來自http://www.w3schools.com。 本文主要是個人學習筆記,將替代手寫的筆記。以此記錄自己的學習過程,記錄不懂的,可以逐漸增加新知識點。 What is XML? XML stands for EXte

原创 nginx模塊開發入門:hello

轉載自Joshua Zhu的博客:http://blog.zhuzhaoyuan.com/2009/08/creating-a-hello-world-nginx-module/ 1. 下載nginx源碼,解壓。 2. 創建hello模

原创 python標準庫logging模塊代碼分析

問題1:如何獲取caller的(文件名,行號,函數名)?       當新增一條log記錄時,最終將調用Logger類的_log方法,這個方法首先會創建一個LogRecord對象。LogRecord對象需要(filename, lin

原创 openvpn體驗

參考:自 “seven” 博客http://liuyu.blog.51cto.com/183345/166047 使用openvpn,不懂原理,遇到一點點的問題,都像一座大山一樣。自己絲毫沒有分析,解決的能力。 今天遇到一個很奇怪的問題

原创 git使用介紹(一)

1. 如何使用GitHub 執行“git remote add origin https://github.com/username/projectname.git",將GitHub的repository鏈接保存到本地的config中。

原创 Unittest使用和代碼簡介

前段時間有學習過unittest這個模塊,但是,沒有熟練使用,還是存在好多疑問。今天又重新花時間學習,比較徹底的搞清楚了。記錄下來,希望對那些有同樣疑問的人,有些幫助。 首先,介紹以下unittest的基本用法。 第1種用法(以下代碼是

原创 How to setup Linux OpenVPN client

參考: 1. http://www.techrepublic.com/blog/opensource/how-to-set-up-a-linux-openvpn-client/1894 2. https://stomp.colorado.

原创 typedef重定義錯誤

記錄一個問題。 Item.h文件: typedef int Item; Link.h文件: #include "Item.h" void LINKinit(int); Link.c文件: #include "stdio.h" #in