diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-30 22:27:18 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-30 22:27:18 +0000 |
commit | c4f4203aaff577fdbe60a7a0976e913dbb77f03e (patch) | |
tree | 2fca5cb9cdc7b8c8d046c81453313c275d7dd5cd /src/util/mq.c | |
parent | e9dbabbabb9edd41bb7d7cb907826abdd8edb257 (diff) | |
download | gnunet-c4f4203aaff577fdbe60a7a0976e913dbb77f03e.tar.gz gnunet-c4f4203aaff577fdbe60a7a0976e913dbb77f03e.zip |
enable setting per-envelope or per-queue transmission options with MQ API
Diffstat (limited to 'src/util/mq.c')
-rw-r--r-- | src/util/mq.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/util/mq.c b/src/util/mq.c index 1638d7e0c..a4ea5e39d 100644 --- a/src/util/mq.c +++ b/src/util/mq.c | |||
@@ -63,6 +63,26 @@ struct GNUNET_MQ_Envelope | |||
63 | * Closure for @e send_cb | 63 | * Closure for @e send_cb |
64 | */ | 64 | */ |
65 | void *sent_cls; | 65 | void *sent_cls; |
66 | |||
67 | /** | ||
68 | * Flags that were set for this envelope by | ||
69 | * #GNUNET_MQ_env_set_options(). Only valid if | ||
70 | * @e have_custom_options is set. | ||
71 | */ | ||
72 | uint64_t flags; | ||
73 | |||
74 | /** | ||
75 | * Additional options buffer set for this envelope by | ||
76 | * #GNUNET_MQ_env_set_options(). Only valid if | ||
77 | * @e have_custom_options is set. | ||
78 | */ | ||
79 | const void *extra; | ||
80 | |||
81 | /** | ||
82 | * Did the application call #GNUNET_MQ_env_set_options()? | ||
83 | */ | ||
84 | int have_custom_options; | ||
85 | |||
66 | }; | 86 | }; |
67 | 87 | ||
68 | 88 | ||
@@ -135,6 +155,18 @@ struct GNUNET_MQ_Handle | |||
135 | struct GNUNET_SCHEDULER_Task *continue_task; | 155 | struct GNUNET_SCHEDULER_Task *continue_task; |
136 | 156 | ||
137 | /** | 157 | /** |
158 | * Additional options buffer set for this queue by | ||
159 | * #GNUNET_MQ_set_options(). Default is 0. | ||
160 | */ | ||
161 | const void *default_extra; | ||
162 | |||
163 | /** | ||
164 | * Flags that were set for this queue by | ||
165 | * #GNUNET_MQ_set_options(). Default is 0. | ||
166 | */ | ||
167 | uint64_t default_flags; | ||
168 | |||
169 | /** | ||
138 | * Next id that should be used for the @e assoc_map, | 170 | * Next id that should be used for the @e assoc_map, |
139 | * initialized lazily to a random value together with | 171 | * initialized lazily to a random value together with |
140 | * @e assoc_map | 172 | * @e assoc_map |
@@ -1040,4 +1072,84 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev) | |||
1040 | GNUNET_free (ev); | 1072 | GNUNET_free (ev); |
1041 | } | 1073 | } |
1042 | 1074 | ||
1075 | |||
1076 | /** | ||
1077 | * Function to obtain the current envelope from | ||
1078 | * within #GNUNET_MQ_SendImpl implementations. | ||
1079 | * | ||
1080 | * @param mq message queue to interrogate | ||
1081 | * @return the current envelope | ||
1082 | */ | ||
1083 | struct GNUNET_MQ_Envelope * | ||
1084 | GNUNET_MQ_get_current_envelope (struct GNUNET_MQ_Handle *mq) | ||
1085 | { | ||
1086 | return mq->current_envelope; | ||
1087 | } | ||
1088 | |||
1089 | |||
1090 | /** | ||
1091 | * Set application-specific options for this envelope. | ||
1092 | * Overrides the options set for the queue with | ||
1093 | * #GNUNET_MQ_set_options() for this message only. | ||
1094 | * | ||
1095 | * @param env message to set options for | ||
1096 | * @param flags flags to use (meaning is queue-specific) | ||
1097 | * @param extra additional buffer for further data (also queue-specific) | ||
1098 | */ | ||
1099 | void | ||
1100 | GNUNET_MQ_env_set_options (struct GNUNET_MQ_Envelope *env, | ||
1101 | uint64_t flags, | ||
1102 | const void *extra) | ||
1103 | { | ||
1104 | env->flags = flags; | ||
1105 | env->extra = extra; | ||
1106 | env->have_custom_options = GNUNET_YES; | ||
1107 | } | ||
1108 | |||
1109 | |||
1110 | /** | ||
1111 | * Get application-specific options for this envelope. | ||
1112 | * | ||
1113 | * @param env message to set options for | ||
1114 | * @param[out] flags set to flags to use (meaning is queue-specific) | ||
1115 | * @return extra additional buffer for further data (also queue-specific) | ||
1116 | */ | ||
1117 | const void * | ||
1118 | GNUNET_MQ_env_get_options (struct GNUNET_MQ_Envelope *env, | ||
1119 | uint64_t *flags) | ||
1120 | { | ||
1121 | struct GNUNET_MQ_Handle *mq = env->parent_queue; | ||
1122 | |||
1123 | if (GNUNET_YES == env->have_custom_options) | ||
1124 | { | ||
1125 | *flags = env->flags; | ||
1126 | return env->extra; | ||
1127 | } | ||
1128 | if (NULL == mq) | ||
1129 | { | ||
1130 | *flags = 0; | ||
1131 | return NULL; | ||
1132 | } | ||
1133 | *flags = mq->default_flags; | ||
1134 | return mq->default_extra; | ||
1135 | } | ||
1136 | |||
1137 | |||
1138 | /** | ||
1139 | * Set application-specific options for this queue. | ||
1140 | * | ||
1141 | * @param mq message queue to set options for | ||
1142 | * @param flags flags to use (meaning is queue-specific) | ||
1143 | * @param extra additional buffer for further data (also queue-specific) | ||
1144 | */ | ||
1145 | void | ||
1146 | GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq, | ||
1147 | uint64_t flags, | ||
1148 | const void *extra) | ||
1149 | { | ||
1150 | mq->default_flags = flags; | ||
1151 | mq->default_extra = extra; | ||
1152 | } | ||
1153 | |||
1154 | |||
1043 | /* end of mq.c */ | 1155 | /* end of mq.c */ |