]> git.sesse.net Git - cubemap/commitdiff
Merge branch 'master' of /srv/git.sesse.net/www/cubemap
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 21 Apr 2013 11:56:03 +0000 (13:56 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 21 Apr 2013 11:56:03 +0000 (13:56 +0200)
1  2 
serverpool.cpp
stream.cpp
thread.cpp

diff --combined serverpool.cpp
index 9582041fb9e0727509e6226b7baaba34c8f3417b,f8e64aaeb962e75b139e3cc3e9098161abda6990..590e0f53b30a5c095e3b57a7a1a5a470093574fb
@@@ -1,7 -1,11 +1,7 @@@
  #include <assert.h>
 -#include <errno.h>
 -#include <google/protobuf/repeated_field.h>
  #include <stdlib.h>
 -#include <unistd.h>
  
  #include "client.h"
 -#include "log.h"
  #include "server.h"
  #include "serverpool.h"
  #include "state.pb.h"
@@@ -12,13 -16,18 +12,18 @@@ using namespace std
  ServerPool::ServerPool(int size)
        : servers(new Server[size]),
          num_servers(size),
-         clients_added(0)
+         clients_added(0),
+         num_http_streams(0)
  {
  }
  
  ServerPool::~ServerPool()
  {
        delete[] servers;
+       for (size_t i = 0; i < udp_streams.size(); ++i) {
+               delete udp_streams[i];
+       }
  }
        
  CubemapStateProto ServerPool::serialize()
@@@ -65,24 -74,25 +70,25 @@@ int ServerPool::lookup_stream_by_url(co
  
  int ServerPool::add_stream(const string &url, size_t backlog_size, Stream::Encoding encoding)
  {
-       int stream_index = -1;
+       // Adding more HTTP streams after UDP streams would cause the UDP stream
+       // indices to move around, which is obviously not good.
+       assert(udp_streams.empty());
        for (int i = 0; i < num_servers; ++i) {
-               int stream_index2 = servers[i].add_stream(url, backlog_size, encoding);
-               if (i == 0) {
-                       stream_index = stream_index2;
-               } else {
-                       // Verify that all servers have this under the same stream index.
-                       assert(stream_index == stream_index2);
-               }
+               int stream_index = servers[i].add_stream(url, backlog_size, encoding);
+               assert(stream_index == num_http_streams);
        }
-       return stream_index;
+       return num_http_streams++;
  }
  
  int ServerPool::add_stream_from_serialized(const StreamProto &stream, const vector<int> &data_fds)
  {
+       // Adding more HTTP streams after UDP streams would cause the UDP stream
+       // indices to move around, which is obviously not good.
+       assert(udp_streams.empty());
        assert(!data_fds.empty());
        string contents;
-       int stream_index = -1;
        for (int i = 0; i < num_servers; ++i) {
                int data_fd;
                if (i < int(data_fds.size())) {
                        data_fd = make_tempfile(contents);
                }
  
-               int stream_index2 = servers[i].add_stream_from_serialized(stream, data_fd);
-               if (i == 0) {
-                       stream_index = stream_index2;
-               } else {
-                       // Verify that all servers have this under the same stream index.
-                       assert(stream_index == stream_index2);
-               }
+               int stream_index = servers[i].add_stream_from_serialized(stream, data_fd);
+               assert(stream_index == num_http_streams);
        }
  
        // Close and delete any leftovers, if the number of servers was reduced.
                safe_close(data_fds[i]);  // Implicitly deletes the file.
        }
  
-       return stream_index;
+       return num_http_streams++;
+ }
+       
+ int ServerPool::add_udpstream(const sockaddr_in6 &dst, MarkPool *mark_pool)
+ {
+       udp_streams.push_back(new UDPStream(dst, mark_pool));
+       return num_http_streams + udp_streams.size() - 1;
  }
  
  void ServerPool::set_header(int stream_index, const string &http_header, const string &stream_header)
  {
+       assert(stream_index >= 0 && stream_index < ssize_t(num_http_streams + udp_streams.size()));
+       if (stream_index >= num_http_streams) {
+               // UDP stream. TODO: Log which stream this is.
+               if (!stream_header.empty()) {
+                       log(WARNING, "Trying to send stream format with headers to a UDP destination. This is unlikely to work well.");
+               }
+               // Ignore the HTTP header.
+               return;
+       }
+       // HTTP stream.
        for (int i = 0; i < num_servers; ++i) {
                servers[i].set_header(stream_index, http_header, stream_header);
        }
  
  void ServerPool::add_data(int stream_index, const char *data, size_t bytes)
  {
+       assert(stream_index >= 0 && stream_index < ssize_t(num_http_streams + udp_streams.size()));
+       if (stream_index >= num_http_streams) {
+               // UDP stream.
+               udp_streams[stream_index - num_http_streams]->send(data, bytes);
+               return;
+       }
+       // HTTP stream.
        for (int i = 0; i < num_servers; ++i) {
                servers[i].add_data_deferred(stream_index, data, bytes);
        }
diff --combined stream.cpp
index 425477c0bedd424ff1a507220c0fb1fed952665b,b8604012f628fcce938e5861908af82436e1e0d6..6a8402794312ad4a4985da3478bddeffcafa5625
@@@ -3,7 -3,7 +3,7 @@@
  #include <netinet/in.h>
  #include <stdlib.h>
  #include <string.h>
 -#include <unistd.h>
 +#include <sys/types.h>
  #include <string>
  #include <vector>
  
@@@ -222,7 -222,7 +222,7 @@@ void Stream::add_data_deferred(const ch
  
                queued_data.push_back(iov);
        } else {
-               assert(encoding == Stream::STREAM_ENCODING_RAW);
+               assert(false);
        }
  }
  
diff --combined thread.cpp
index 2aaf34f11441cefe3befcba7b33cc08c6d4f6db6,98c743c594313704281c2360f2d5688c0c691cab..72bc320b0b32359dcbbe51352b2df8ca77850a45
@@@ -1,5 -1,6 +1,5 @@@
  #include <assert.h>
  #include <errno.h>
 -#include <fcntl.h>
  #include <poll.h>
  #include <signal.h>
  #include <stdio.h>
@@@ -40,6 -41,7 +40,7 @@@ void *Thread::do_work_thunk(void *arg
        // (This isn't strictly required, but it makes it easier to debug that indeed
        // SIGUSR1 was what woke us up.)
        sigset_t set;
+       sigemptyset(&set);
        sigaddset(&set, SIGHUP);
        int err = pthread_sigmask(SIG_BLOCK, &set, NULL);
        if (err != 0) {