単純なソケット パラメーターを持つ関数を作成し、そのソケット ( 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
機能はどうですか?