Просмотр исходного кода

should be ready now

pull/30/head
devgs 13 лет назад
Родитель
Сommit
070e0368a0
1 измененных файлов: 19 добавлений и 4 удалений
  1. 19
    4
      ngx_http_uploadprogress_module.c

+ 19
- 4
ngx_http_uploadprogress_module.c Просмотреть файл

@@ -33,6 +33,7 @@ struct ngx_http_uploadprogress_node_s {
33 33
     off_t                            length;
34 34
     ngx_uint_t                       done;
35 35
     ngx_uint_t                       sequence;
36
+    ngx_uint_t                       sent_portion;
36 37
     time_t                           timeout;
37 38
     struct ngx_http_uploadprogress_node_s *prev;
38 39
     struct ngx_http_uploadprogress_node_s *next;
@@ -667,10 +668,22 @@ static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
667 668
         {
668 669
             u_char      datagram_buf[1024];
669 670
             u_char *    end;
670
-
671
-            end = ngx_snprintf(datagram_buf, sizeof(datagram_buf), "{\"id\" : \"%V\", \"sequence\", \"size\" : %u, \"uploaded\" : %u}", id, up->sequence, up->length, up->rest);
672
-            sendto(upcf->udp_socket, datagram_buf, end - datagram_buf, 0, (struct sockaddr*)upcf->progress_server.sockaddr, upcf->progress_server.socklen);
673
-            ++up->sequence;
671
+            off_t       uploaded;
672
+            ngx_uint_t  portion;
673
+
674
+            uploaded = up->length - up->rest;
675
+            if(up->length)
676
+                portion = 100 * uploaded / up->length;
677
+            else
678
+                portion = 100;
679
+            if(portion > up->sent_portion)
680
+            {
681
+                end = ngx_snprintf(datagram_buf, sizeof(datagram_buf), "{\"id\" : \"%V\", \"sequence\" : %d, \"size\" : %uO, \"uploaded\" : %uO }",
682
+                                   id, up->sequence, up->length, uploaded);
683
+                sendto(upcf->udp_socket, datagram_buf, end - datagram_buf, 0, (struct sockaddr*)upcf->progress_server.sockaddr, upcf->progress_server.socklen);
684
+                up->sent_portion = portion;
685
+                ++up->sequence;
686
+            }
674 687
         }
675 688
         ngx_log_debug3(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
676 689
                        "upload-progress: read_event_handler storing rest %uO/%uO for %V", up->rest, up->length, id);
@@ -1184,6 +1197,7 @@ ngx_http_uploadprogress_handler(ngx_http_request_t * r)
1184 1197
     up->length = 0;
1185 1198
     up->timeout = 0;
1186 1199
     up->sequence = 0;
1200
+    up->sent_portion = 0;
1187 1201
 
1188 1202
     up->next = ctx->list_head.next;
1189 1203
     up->next->prev = up;
@@ -1525,6 +1539,7 @@ ngx_http_uploadprogress_errortracker(ngx_http_request_t * r)
1525 1539
         up->length = 0;
1526 1540
         up->timeout = 0;
1527 1541
         up->sequence = 0;
1542
+        up->sent_portion = 0;
1528 1543
 
1529 1544
         ngx_memcpy(up->data, id->data, id->len);
1530 1545
 

Загрузка…
Отмена
Сохранить