非阻塞網路函式封裝不一致

2021-04-20 03:37:16 字數 1783 閱讀 4761

ace的非阻塞網路函式引數設計有不合理的地方。

ace_sock_stream

和ace_sock_connector

在非阻塞的的呼叫的介面對於

ace_time_value *timeout

引數的使用不一致,乙個要使用

null

,乙個卻要使用

ace_time_value::zero。

ace_sock_stream

,非阻塞呼叫

send

函式的時候【注】,

timeout

引數必須填寫為

null

。它最後呼叫的是

ace::send

。將ace_time_value

填寫為ace_time_value::zero

(0,0

)是不行的。如果填寫

ace_time_value::zero

,會大大降低這個非阻塞呼叫的效能。

ssize_t

ace::send (ace_handle handle,

const void *buf,

size_t n,

int flags,

const ace_time_value *timeout)

}timeout);

注意使用非阻塞的的

io要呼叫

recv

,send

函式,而不要呼叫

recv_n,send_n

這些函式介面,這些函式介面如果

timeout

引數傳遞

null

,表示阻塞。

另外非阻塞

io還是要自己設定

socket

的選項。

但是ace_sock_connector

卻採用另外乙個封裝方式,其是傳入乙個

null

表示阻塞,而傳入

ace_time_value::zero

(0,0

)表示進行非阻塞鏈結操作。

* @param timeoutpointer to an @c ace_time_value object with amount

*of time to wait to connect. if the pointer is 0

*then the call blocks until the connection attempt *

is complete, whether it succeeds or fails.if

**timeout == then the connection is done

*using nonblocking mode.in this case, if the

*connection can't be made immediately, this method

*returns -1 and errno == ewouldblock.

int connect (ace_sock_stream &new_stream,

const ace_addr &remote_sap,

const ace_time_value *timeout = 0,

const ace_addr &local_sap = ace_addr::sap_any,

int reuse_addr = 0,

int flags = 0,

int perms = 0,

int protocol = 0);

大家在處理這些

io時務必當心。

快取不一致

當程式在執行過程中,會將運算需要的資料從主存複製乙份到cpu的快取記憶體當中,那麼cpu進行計算時就可以直接從它的快取記憶體讀取資料和向其中寫入資料,當運算結束之後,再將快取記憶體中的資料重新整理到主存當中。舉個簡單的例子 i i 1。當執行緒執行這個語句時,會先從主存當中讀取i的值,然後複製乙份到...

strongswan 對等體封裝模式不一致的處理

ipsec的封裝模式有兩種 transport模式和tunnel模式。當對等體的封裝模式不一致 即一方為transport模式,另一方為tunnel模式 時,雙方協商的結果是建立tunnel模式的ipsec會話。duta transport dutb tunnel 以ikev2為例分析。在上圖中,假...

version magic 不一致問題

碰到乙個問題,在開發過程中發現以前編譯的模組載入失敗了。wlan version magic 4.1.15 gfb2dbf6 smp preempt mod unload armv7 p2v8 should be 4.1.15 ge5de83b dirty smp preempt mod unloa...