]> jfr.im git - solanum.git/blobdiff - src/send.c
ssl sync with http://hg.angelforce.ru/charybdis-old
[solanum.git] / src / send.c
index 14898865a0c1db1475865662fb072c7cb9fe5c37..d2d603fde4ce423349e6f4b4a052445645129a1c 100644 (file)
@@ -37,7 +37,7 @@
 #include "sprintf_irc.h"
 #include "s_conf.h"
 #include "s_newconf.h"
-#include "s_log.h"
+#include "logger.h"
 #include "hook.h"
 #include "monitor.h"
 
@@ -149,6 +149,14 @@ send_queued(struct Client *to)
        if(IsIOError(to))
                return;
 
+       /* Something wants us to not send anything currently */\r
+       /* if(IsCork(to))\r
+               return; */\r
+\r
+       /* try to flush later when the write event resets this */\r
+       if(IsFlush(to))\r
+               return;
+
 #ifdef USE_IODEBUG_HOOKS
        hd.client = to;
        if(to->localClient->buf_sendq.list.head)
@@ -173,6 +181,8 @@ send_queued(struct Client *to)
 #endif
      
 
+                       ClearFlush(to);
+
                        to->localClient->sendB += retlen;
                        me.localClient->sendB += retlen;
                        if(to->localClient->sendB > 1023)
@@ -193,9 +203,26 @@ send_queued(struct Client *to)
                        return;
                }
        }
-       if(rb_linebuf_len(&to->localClient->buf_sendq))
-       rb_setselect(to->localClient->F, RB_SELECT_WRITE,
-                              send_queued_write, to);
+
+       if(rb_linebuf_len(&to->localClient->buf_sendq))\r
+       {\r
+               SetFlush(to);\r
+               rb_setselect(to->localClient->F, RB_SELECT_WRITE,\r
+                              send_queued_write, to);\r
+       }\r
+       else\r
+               ClearFlush(to);
+}
+
+void\r
+send_pop_queue(struct Client *to)\r
+{\r
+       if(to->from != NULL)\r
+               to = to->from;\r
+       if(!MyConnect(to) || IsIOError(to))\r
+               return;\r
+       if(rb_linebuf_len(&to->localClient->buf_sendq) > 0)\r
+               send_queued(to);\r
 }
 
 /* send_queued_write()
@@ -208,73 +235,10 @@ static void
 send_queued_write(rb_fde_t *F, void *data)
 {
        struct Client *to = data;
-       /*ClearFlush(to);*/
+       ClearFlush(to);
        send_queued(to);
 }
 
-/* send_queued_slink_write()
- *
- * inputs      - fd to have queue sent, client we're sending to
- * outputs     - contents of queue
- * side effects - write is rescheduled if queue isnt emptied
- */
-void
-send_queued_slink_write(int fd, void *data)
-{
-       struct Client *to = data;
-       int retlen;
-
-       /*
-        ** Once socket is marked dead, we cannot start writing to it,
-        ** even if the error is removed...
-        */
-       if(IsIOError(to))
-               return;
-
-       /* Next, lets try to write some data */
-       if(to->localClient->slinkq)
-       {
-               retlen = write(to->localClient->ctrlfd,
-                             to->localClient->slinkq + to->localClient->slinkq_ofs,
-                             to->localClient->slinkq_len);
-
-               if(retlen < 0)
-               {
-                       /* If we have a fatal error */
-                       if(!rb_ignore_errno(errno))
-                       {
-                               dead_link(to);
-                               return;
-                       }
-               }
-               /* 0 bytes is an EOF .. */
-               else if(retlen == 0)
-               {
-                       dead_link(to);
-                       return;
-               }
-               else
-               {
-                       to->localClient->slinkq_len -= retlen;
-
-                       s_assert(to->localClient->slinkq_len >= 0);
-                       if(to->localClient->slinkq_len)
-                               to->localClient->slinkq_ofs += retlen;
-                       else
-                       {
-                               to->localClient->slinkq_ofs = 0;
-                               MyFree(to->localClient->slinkq);
-                               to->localClient->slinkq = NULL;
-                       }
-               }
-       }
-
-       /* if we have any more data, reschedule a write */
-       if(to->localClient->slinkq_len)
-               rb_setselect(to->localClient->ctrlfd,
-                              RB_SELECT_WRITE, send_queued_slink_write, to);
-}
-
 /* sendto_one()
  *
  * inputs      - client to send to, va_args
@@ -453,7 +417,7 @@ sendto_server(struct Client *one, struct Channel *chptr, unsigned long caps,
        va_list args;
        struct Client *target_p;
        rb_dlink_node *ptr;
-       rb_dlink_node *rb_free(;
+       rb_dlink_node *next_ptr;
        buf_head_t linebuf;
 
        /* noone to send to.. */
@@ -468,7 +432,7 @@ sendto_server(struct Client *one, struct Channel *chptr, unsigned long caps,
        rb_linebuf_putmsg(&linebuf, format, &args, NULL);
        va_end(args);
 
-       RB_DLINK_FOREACH_SAFE(ptr, rb_free(, serv_list.head)
+       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head)
        {
                target_p = ptr->data;
 
@@ -509,7 +473,7 @@ sendto_channel_flags(struct Client *one, int type, struct Client *source_p,
        struct Client *target_p;
        struct membership *msptr;
        rb_dlink_node *ptr;
-       rb_dlink_node *rb_free(;
+       rb_dlink_node *next_ptr;
 
        rb_linebuf_newbuf(&rb_linebuf_local);
        rb_linebuf_newbuf(&rb_linebuf_name);
@@ -533,7 +497,7 @@ sendto_channel_flags(struct Client *one, int type, struct Client *source_p,
        rb_linebuf_putmsg(&rb_linebuf_name, NULL, NULL, ":%s %s", source_p->name, buf);
        rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf);
 
-       RB_DLINK_FOREACH_SAFE(ptr, rb_free(, chptr->members.head)
+       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head)
        {
                msptr = ptr->data;
                target_p = msptr->client_p;
@@ -589,7 +553,7 @@ sendto_channel_local(int type, struct Channel *chptr, const char *pattern, ...)
        struct membership *msptr;
        struct Client *target_p;
        rb_dlink_node *ptr;
-       rb_dlink_node *rb_free(;
+       rb_dlink_node *next_ptr;
        
        rb_linebuf_newbuf(&linebuf); 
        
@@ -597,7 +561,7 @@ sendto_channel_local(int type, struct Channel *chptr, const char *pattern, ...)
        rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
        va_end(args);
 
-       RB_DLINK_FOREACH_SAFE(ptr, rb_free(, chptr->locmembers.head)
+       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
        {
                msptr = ptr->data;
                target_p = msptr->client_p;
@@ -629,7 +593,7 @@ sendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr,
        struct membership *msptr;
        struct Client *target_p;
        rb_dlink_node *ptr;
-       rb_dlink_node *rb_free(;
+       rb_dlink_node *next_ptr;
        
        rb_linebuf_newbuf(&linebuf); 
        
@@ -637,7 +601,7 @@ sendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr,
        rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
        va_end(args);
 
-       RB_DLINK_FOREACH_SAFE(ptr, rb_free(, chptr->locmembers.head)
+       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
        {
                msptr = ptr->data;
                target_p = msptr->client_p;
@@ -672,7 +636,7 @@ sendto_common_channels_local(struct Client *user, const char *pattern, ...)
 {
        va_list args;
        rb_dlink_node *ptr;
-       rb_dlink_node *rb_free(;
+       rb_dlink_node *next_ptr;
        rb_dlink_node *uptr;
        rb_dlink_node *next_uptr;
        struct Channel *chptr;
@@ -688,7 +652,7 @@ sendto_common_channels_local(struct Client *user, const char *pattern, ...)
 
        ++current_serial;
 
-       RB_DLINK_FOREACH_SAFE(ptr, rb_free(, user->user->channel.head)
+       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head)
        {
                mscptr = ptr->data;
                chptr = mscptr->chptr;
@@ -730,7 +694,7 @@ sendto_common_channels_local_butone(struct Client *user, const char *pattern, ..
 {
        va_list args;
        rb_dlink_node *ptr;
-       rb_dlink_node *rb_free(;
+       rb_dlink_node *next_ptr;
        rb_dlink_node *uptr;
        rb_dlink_node *next_uptr;
        struct Channel *chptr;
@@ -748,7 +712,7 @@ sendto_common_channels_local_butone(struct Client *user, const char *pattern, ..
        /* Skip them -- jilles */
        user->serial = current_serial;
 
-       RB_DLINK_FOREACH_SAFE(ptr, rb_free(, user->user->channel.head)
+       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head)
        {
                mscptr = ptr->data;
                chptr = mscptr->chptr;
@@ -784,7 +748,7 @@ sendto_match_butone(struct Client *one, struct Client *source_p,
        va_list args;
        struct Client *target_p;
        rb_dlink_node *ptr;
-       rb_dlink_node *rb_free(;
+       rb_dlink_node *next_ptr;
        buf_head_t rb_linebuf_local;
        buf_head_t rb_linebuf_name;
        buf_head_t rb_linebuf_id;
@@ -811,7 +775,7 @@ sendto_match_butone(struct Client *one, struct Client *source_p,
 
        if(what == MATCH_HOST)
        {
-               RB_DLINK_FOREACH_SAFE(ptr, rb_free(, lclient_list.head)
+               RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
                {
                        target_p = ptr->data;
 
@@ -822,7 +786,7 @@ sendto_match_butone(struct Client *one, struct Client *source_p,
        /* what = MATCH_SERVER, if it doesnt match us, just send remote */
        else if(match(mask, me.name))
        {
-               RB_DLINK_FOREACH_SAFE(ptr, rb_free(, lclient_list.head)
+               RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
                {
                        target_p = ptr->data;
                        _send_linebuf(target_p, &rb_linebuf_local);
@@ -929,7 +893,7 @@ sendto_monitor(struct monitor *monptr, const char *pattern, ...)
        buf_head_t linebuf;
        struct Client *target_p;
        rb_dlink_node *ptr;
-       rb_dlink_node *rb_free(;
+       rb_dlink_node *next_ptr;
        
        rb_linebuf_newbuf(&linebuf); 
        
@@ -937,7 +901,7 @@ sendto_monitor(struct monitor *monptr, const char *pattern, ...)
        rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
        va_end(args);
 
-       RB_DLINK_FOREACH_SAFE(ptr, rb_free(, monptr->users.head)
+       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, monptr->users.head)
        {
                target_p = ptr->data;
 
@@ -1005,7 +969,7 @@ sendto_realops_flags(int flags, int level, const char *pattern, ...)
 {
        struct Client *client_p;
        rb_dlink_node *ptr;
-       rb_dlink_node *rb_free(;
+       rb_dlink_node *next_ptr;
        va_list args;
        buf_head_t linebuf;
 
@@ -1016,7 +980,7 @@ sendto_realops_flags(int flags, int level, const char *pattern, ...)
                       ":%s NOTICE * :*** Notice -- ", me.name);
        va_end(args);
 
-       RB_DLINK_FOREACH_SAFE(ptr, rb_free(, local_oper_list.head)
+       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head)
        {
                client_p = ptr->data;
 
@@ -1047,7 +1011,7 @@ sendto_realops_snomask(int flags, int level, const char *pattern, ...)
        char *snobuf;
        struct Client *client_p;
        rb_dlink_node *ptr;
-       rb_dlink_node *rb_free(;
+       rb_dlink_node *next_ptr;
        va_list args;
        buf_head_t linebuf;
 
@@ -1083,7 +1047,7 @@ sendto_realops_snomask(int flags, int level, const char *pattern, ...)
        }
        level &= ~L_NETWIDE;
 
-       RB_DLINK_FOREACH_SAFE(ptr, rb_free(, local_oper_list.head)
+       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head)
        {
                client_p = ptr->data;
 
@@ -1112,7 +1076,7 @@ sendto_realops_snomask_from(int flags, int level, struct Client *source_p,
 {
        struct Client *client_p;
        rb_dlink_node *ptr;
-       rb_dlink_node *rb_free(;
+       rb_dlink_node *next_ptr;
        va_list args;
        buf_head_t linebuf;
 
@@ -1123,7 +1087,7 @@ sendto_realops_snomask_from(int flags, int level, struct Client *source_p,
                       ":%s NOTICE * :*** Notice -- ", source_p->name);
        va_end(args);
 
-       RB_DLINK_FOREACH_SAFE(ptr, rb_free(, local_oper_list.head)
+       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head)
        {
                client_p = ptr->data;
 
@@ -1155,7 +1119,7 @@ sendto_wallops_flags(int flags, struct Client *source_p, const char *pattern, ..
 {
        struct Client *client_p;
        rb_dlink_node *ptr;
-       rb_dlink_node *rb_free(;
+       rb_dlink_node *next_ptr;
        va_list args;
        buf_head_t linebuf;
 
@@ -1172,7 +1136,7 @@ sendto_wallops_flags(int flags, struct Client *source_p, const char *pattern, ..
 
        va_end(args);
 
-       RB_DLINK_FOREACH_SAFE(ptr, rb_free(, IsPerson(source_p) && flags == UMODE_WALLOP ? lclient_list.head : local_oper_list.head)
+       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, IsPerson(source_p) && flags == UMODE_WALLOP ? lclient_list.head : local_oper_list.head)
        {
                client_p = ptr->data;
 
@@ -1225,7 +1189,7 @@ kill_client_serv_butone(struct Client *one, struct Client *target_p, const char
        va_list args;
        struct Client *client_p;
        rb_dlink_node *ptr;
-       rb_dlink_node *rb_free(;
+       rb_dlink_node *next_ptr;
        buf_head_t rb_linebuf_id;
        buf_head_t rb_linebuf_name;
 
@@ -1241,7 +1205,7 @@ kill_client_serv_butone(struct Client *one, struct Client *target_p, const char
        rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s KILL %s :%s",
                       use_id(&me), use_id(target_p), buf);
 
-       RB_DLINK_FOREACH_SAFE(ptr, rb_free(, serv_list.head)
+       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head)
        {
                client_p = ptr->data;