Lines Matching refs:conn

22 static int dict_connection_parse_handshake(struct dict_connection *conn,
37 if (str_parse_uint(line, &conn->minor_version, &line) < 0)
52 conn->value_type = (enum dict_data_type)value_type_num;
60 conn->username = i_strdup_until(username, line - 1);
70 conn->name = i_strdup(name);
74 static int dict_connection_dict_init(struct dict_connection *conn)
87 if (strcmp(strlist[i], conn->name) == 0)
93 conn->name);
99 dict_set.value_type = conn->value_type;
100 dict_set.username = conn->username;
102 if (dict_init(uri, &dict_set, &conn->dict, &error) < 0) {
105 conn->name, error);
111 static void dict_connection_input_more(struct dict_connection *conn)
116 timeout_remove(&conn->to_input);
118 while ((line = i_stream_next_line(conn->input)) != NULL) {
120 ret = dict_command_input(conn, line);
123 dict_connection_destroy(conn);
126 if (array_count(&conn->cmds) >= DICT_CONN_MAX_PENDING_COMMANDS) {
127 io_remove(&conn->io);
128 timeout_remove(&conn->to_input);
134 static void dict_connection_input(struct dict_connection *conn)
138 switch (i_stream_read(conn->input)) {
143 dict_connection_destroy(conn);
149 dict_connection_destroy(conn);
153 if (conn->username == NULL) {
155 if ((line = i_stream_next_line(conn->input)) == NULL)
158 if (dict_connection_parse_handshake(conn, line) < 0) {
160 dict_connection_destroy(conn);
163 if (dict_connection_dict_init(conn) < 0) {
164 dict_connection_destroy(conn);
169 dict_connection_input_more(conn);
172 void dict_connection_continue_input(struct dict_connection *conn)
174 if (conn->io != NULL || conn->destroyed)
177 conn->io = io_add(conn->fd, IO_READ, dict_connection_input, conn);
178 if (conn->to_input == NULL)
179 conn->to_input = timeout_add_short(0, dict_connection_input_more, conn);
182 static int dict_connection_output(struct dict_connection *conn)
186 if ((ret = o_stream_flush(conn->output)) < 0) {
187 dict_connection_destroy(conn);
191 dict_connection_cmds_output_more(conn);
197 struct dict_connection *conn;
199 conn = i_new(struct dict_connection, 1);
200 conn->refcount = 1;
201 conn->fd = fd;
202 conn->input = i_stream_create_fd(fd, DICT_CLIENT_MAX_LINE_LENGTH);
203 conn->output = o_stream_create_fd(fd, 128*1024);
204 o_stream_set_no_error_handling(conn->output, TRUE);
205 o_stream_set_flush_callback(conn->output, dict_connection_output, conn);
206 conn->io = io_add(fd, IO_READ, dict_connection_input, conn);
207 i_array_init(&conn->cmds, DICT_CONN_MAX_PENDING_COMMANDS);
210 DLLIST_PREPEND(&dict_connections, conn);
211 return conn;
214 void dict_connection_ref(struct dict_connection *conn)
216 i_assert(conn->refcount > 0);
217 conn->refcount++;
220 bool dict_connection_unref(struct dict_connection *conn)
224 i_assert(conn->refcount > 0);
225 if (--conn->refcount > 0)
228 i_assert(array_count(&conn->cmds) == 0);
232 if (array_is_created(&conn->transactions)) {
233 array_foreach_modifiable(&conn->transactions, transaction) {
239 if (conn->dict != NULL)
240 dict_deinit(&conn->dict);
242 if (array_is_created(&conn->transactions))
243 array_free(&conn->transactions);
245 i_stream_destroy(&conn->input);
246 o_stream_destroy(&conn->output);
248 array_free(&conn->cmds);
249 i_free(conn->name);
250 i_free(conn->username);
251 i_free(conn);
257 static void dict_connection_unref_safe_callback(struct dict_connection *conn)
259 timeout_remove(&conn->to_unref);
260 (void)dict_connection_unref(conn);
263 void dict_connection_unref_safe(struct dict_connection *conn)
265 if (conn->refcount == 1) {
269 if (conn->to_unref == NULL) {
270 conn->to_unref = timeout_add_short(0,
271 dict_connection_unref_safe_callback, conn);
274 (void)dict_connection_unref(conn);
278 void dict_connection_destroy(struct dict_connection *conn)
280 i_assert(!conn->destroyed);
281 i_assert(conn->to_unref == NULL);
286 conn->destroyed = TRUE;
287 DLLIST_REMOVE(&dict_connections, conn);
289 timeout_remove(&conn->to_input);
290 io_remove(&conn->io);
291 i_stream_close(conn->input);
292 o_stream_close(conn->output);
293 if (close(conn->fd) < 0)
295 conn->fd = -1;
303 dict_connection_cmds_output_more(conn);
305 dict_connection_unref(conn);