From: Simon Horman Date: Thu, 24 Nov 2011 01:22:22 +0000 (+0900) Subject: stream: Make classes const X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da327b18bdbd36ad3dc465e07f6700795c684b14;p=openvswitch stream: Make classes const The classes are never modified and may be declared constant. --- diff --git a/lib/stream-fd.c b/lib/stream-fd.c index 2026db6a..7bf5ebd4 100644 --- a/lib/stream-fd.c +++ b/lib/stream-fd.c @@ -45,7 +45,7 @@ struct stream_fd char *unlink_path; }; -static struct stream_class stream_fd_class; +static const struct stream_class stream_fd_class; static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(10, 25); @@ -154,7 +154,7 @@ fd_wait(struct stream *stream, enum stream_wait_type wait) } } -static struct stream_class stream_fd_class = { +static const struct stream_class stream_fd_class = { "fd", /* name */ NULL, /* open */ fd_close, /* close */ diff --git a/lib/stream-provider.h b/lib/stream-provider.h index 2b8ca698..03bf777b 100644 --- a/lib/stream-provider.h +++ b/lib/stream-provider.h @@ -27,7 +27,7 @@ * * This structure should be treated as opaque by implementation. */ struct stream { - struct stream_class *class; + const struct stream_class *class; int state; int error; ovs_be32 remote_ip; @@ -37,8 +37,8 @@ struct stream { char *name; }; -void stream_init(struct stream *, struct stream_class *, int connect_status, - const char *name); +void stream_init(struct stream *, const struct stream_class *, + int connect_status, const char *name); void stream_set_remote_ip(struct stream *, ovs_be32 remote_ip); void stream_set_remote_port(struct stream *, ovs_be16 remote_port); void stream_set_local_ip(struct stream *, ovs_be32 local_ip); @@ -130,11 +130,11 @@ struct stream_class { * * This structure should be treated as opaque by stream implementations. */ struct pstream { - struct pstream_class *class; + const struct pstream_class *class; char *name; }; -void pstream_init(struct pstream *, struct pstream_class *, const char *name); +void pstream_init(struct pstream *, const struct pstream_class *, const char *name); static inline void pstream_assert_class(const struct pstream *pstream, const struct pstream_class *class) { @@ -177,13 +177,13 @@ struct pstream_class { }; /* Active and passive stream classes. */ -extern struct stream_class tcp_stream_class; -extern struct pstream_class ptcp_pstream_class; -extern struct stream_class unix_stream_class; -extern struct pstream_class punix_pstream_class; +extern const struct stream_class tcp_stream_class; +extern const struct pstream_class ptcp_pstream_class; +extern const struct stream_class unix_stream_class; +extern const struct pstream_class punix_pstream_class; #ifdef HAVE_OPENSSL -extern struct stream_class ssl_stream_class; -extern struct pstream_class pssl_pstream_class; +extern const struct stream_class ssl_stream_class; +extern const struct pstream_class pssl_pstream_class; #endif #endif /* stream-provider.h */ diff --git a/lib/stream-ssl.c b/lib/stream-ssl.c index e68cc72b..22d4c99a 100644 --- a/lib/stream-ssl.c +++ b/lib/stream-ssl.c @@ -752,7 +752,7 @@ ssl_wait(struct stream *stream, enum stream_wait_type wait) } } -struct stream_class ssl_stream_class = { +const struct stream_class ssl_stream_class = { "ssl", /* name */ ssl_open, /* open */ ssl_close, /* close */ @@ -772,7 +772,7 @@ struct pssl_pstream int fd; }; -struct pstream_class pssl_pstream_class; +const struct pstream_class pssl_pstream_class; static struct pssl_pstream * pssl_pstream_cast(struct pstream *pstream) @@ -857,7 +857,7 @@ pssl_wait(struct pstream *pstream) poll_fd_wait(pssl->fd, POLLIN); } -struct pstream_class pssl_pstream_class = { +const struct pstream_class pssl_pstream_class = { "pssl", pssl_open, pssl_close, diff --git a/lib/stream-tcp.c b/lib/stream-tcp.c index d92fe3af..9a7614db 100644 --- a/lib/stream-tcp.c +++ b/lib/stream-tcp.c @@ -84,7 +84,7 @@ tcp_open(const char *name, char *suffix, struct stream **streamp) } } -struct stream_class tcp_stream_class = { +const struct stream_class tcp_stream_class = { "tcp", /* name */ tcp_open, /* open */ NULL, /* close */ @@ -134,7 +134,7 @@ ptcp_accept(int fd, const struct sockaddr *sa, size_t sa_len, return new_tcp_stream(name, fd, 0, sin, streamp); } -struct pstream_class ptcp_pstream_class = { +const struct pstream_class ptcp_pstream_class = { "ptcp", ptcp_open, NULL, diff --git a/lib/stream-unix.c b/lib/stream-unix.c index 14680ac5..d7dde8fc 100644 --- a/lib/stream-unix.c +++ b/lib/stream-unix.c @@ -63,7 +63,7 @@ unix_open(const char *name, char *suffix, struct stream **streamp) bind_path, streamp); } -struct stream_class unix_stream_class = { +const struct stream_class unix_stream_class = { "unix", /* name */ unix_open, /* open */ NULL, /* close */ @@ -119,7 +119,7 @@ punix_accept(int fd, const struct sockaddr *sa, size_t sa_len, return new_fd_stream(name, fd, 0, NULL, streamp); } -struct pstream_class punix_pstream_class = { +const struct pstream_class punix_pstream_class = { "punix", punix_open, NULL, diff --git a/lib/stream.c b/lib/stream.c index 8f567ca3..9ba4c518 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -49,7 +49,7 @@ enum stream_state { SCS_DISCONNECTED /* Connection failed or connection closed. */ }; -static struct stream_class *stream_classes[] = { +static const struct stream_class *stream_classes[] = { &tcp_stream_class, &unix_stream_class, #ifdef HAVE_OPENSSL @@ -57,7 +57,7 @@ static struct stream_class *stream_classes[] = { #endif }; -static struct pstream_class *pstream_classes[] = { +static const struct pstream_class *pstream_classes[] = { &ptcp_pstream_class, &punix_pstream_class, #ifdef HAVE_OPENSSL @@ -73,7 +73,7 @@ check_stream_classes(void) size_t i; for (i = 0; i < ARRAY_SIZE(stream_classes); i++) { - struct stream_class *class = stream_classes[i]; + const struct stream_class *class = stream_classes[i]; assert(class->name != NULL); assert(class->open != NULL); if (class->close || class->recv || class->send || class->run @@ -88,7 +88,7 @@ check_stream_classes(void) } for (i = 0; i < ARRAY_SIZE(pstream_classes); i++) { - struct pstream_class *class = pstream_classes[i]; + const struct pstream_class *class = pstream_classes[i]; assert(class->name != NULL); assert(class->listen != NULL); if (class->close || class->accept || class->wait) { @@ -154,7 +154,7 @@ stream_usage(const char *name, bool active, bool passive, * a null pointer into '*classp' if 'name' is in the wrong form or if no such * class exists. */ static int -stream_lookup_class(const char *name, struct stream_class **classp) +stream_lookup_class(const char *name, const struct stream_class **classp) { size_t prefix_len; size_t i; @@ -167,7 +167,7 @@ stream_lookup_class(const char *name, struct stream_class **classp) return EAFNOSUPPORT; } for (i = 0; i < ARRAY_SIZE(stream_classes); i++) { - struct stream_class *class = stream_classes[i]; + const struct stream_class *class = stream_classes[i]; if (strlen(class->name) == prefix_len && !memcmp(class->name, name, prefix_len)) { *classp = class; @@ -182,7 +182,7 @@ stream_lookup_class(const char *name, struct stream_class **classp) int stream_verify_name(const char *name) { - struct stream_class *class; + const struct stream_class *class; return stream_lookup_class(name, &class); } @@ -196,7 +196,7 @@ stream_verify_name(const char *name) int stream_open(const char *name, struct stream **streamp) { - struct stream_class *class; + const struct stream_class *class; struct stream *stream; char *suffix_copy; int error; @@ -457,7 +457,7 @@ stream_send_wait(struct stream *stream) * a null pointer into '*classp' if 'name' is in the wrong form or if no such * class exists. */ static int -pstream_lookup_class(const char *name, struct pstream_class **classp) +pstream_lookup_class(const char *name, const struct pstream_class **classp) { size_t prefix_len; size_t i; @@ -470,7 +470,7 @@ pstream_lookup_class(const char *name, struct pstream_class **classp) return EAFNOSUPPORT; } for (i = 0; i < ARRAY_SIZE(pstream_classes); i++) { - struct pstream_class *class = pstream_classes[i]; + const struct pstream_class *class = pstream_classes[i]; if (strlen(class->name) == prefix_len && !memcmp(class->name, name, prefix_len)) { *classp = class; @@ -485,7 +485,7 @@ pstream_lookup_class(const char *name, struct pstream_class **classp) int pstream_verify_name(const char *name) { - struct pstream_class *class; + const struct pstream_class *class; return pstream_lookup_class(name, &class); } @@ -499,7 +499,7 @@ pstream_verify_name(const char *name) int pstream_open(const char *name, struct pstream **pstreamp) { - struct pstream_class *class; + const struct pstream_class *class; struct pstream *pstream; char *suffix_copy; int error; @@ -613,7 +613,7 @@ pstream_wait(struct pstream *pstream) * * The caller retains ownership of 'name'. */ void -stream_init(struct stream *stream, struct stream_class *class, +stream_init(struct stream *stream, const struct stream_class *class, int connect_status, const char *name) { memset(stream, 0, sizeof *stream); @@ -651,7 +651,7 @@ stream_set_local_port(struct stream *stream, ovs_be16 port) } void -pstream_init(struct pstream *pstream, struct pstream_class *class, +pstream_init(struct pstream *pstream, const struct pstream_class *class, const char *name) { pstream->class = class;