我想知道...如果您创建一个具有简单套接字参数的函数,并且您在该函数中执行基本指令,例如为该套接字(setsockopt()
)设置不同的选项,并且在函数存在后它仍然是选项,那么实际的区别是什么?或者我应该将该参数指针指向该套接字,以保留套接字将发生的实际更改。
sctp_enable_events( int socket, int ev_mask )
{
struct sctp_event_subscribe ev;
bzero(&ev, sizeof(ev));
if (ev_mask & SCTP_SNDRCV_INFO_EV)
ev.sctp_data_io_event = 1;
/*code */
if (setsockopt(socket,
IPPROTO_SCTP,
SCTP_EVENTS,
SCTP_SET_EVENTS,
(const char*)&ev,
sizeof(ev)) != 0 ) {
fprintf(where,
"sctp_enable_event: could not set sctp events errno %d\n",
errno);
fflush(where);
exit(1);
}
}
还是像这样?
sctp_enable_events( int *socket, int ev_mask, struct sctp_event_subscribe *ev )
{
if (ev_mask & SCTP_SNDRCV_INFO_EV)
ev->sctp_data_io_event = 1;
/*code */
if (setsockopt(*socket,
IPPROTO_SCTP,
SCTP_EVENTS,
SCTP_SET_EVENTS,
ev,
sizeof(*ev)) != 0 ) {
fprintf(where,
"sctp_enable_event: could not set sctp events errno %d\n",
errno);
fflush(where);
exit(1);
}
}
我知道通过将指针传递给 struct、int、char 等,您可以在函数执行后修改值,如果没有指针,修改将仅在该函数中保持本地,但不会全局更改。
但是setsockopt
功能如何呢?