#include <vos/vutil/log.hh>
#include <vos/vip/socketthread.hh>

using namespace VUtil;
using namespace VIP;

#undef PKTDUMP

void SocketProcessorThread::operator()()
{
    socklen_t socklen = (socklen_t)sizeof(sockaddr_in);
    struct sockaddr_in from;

#ifdef PKTDUMP
    FILE* f = fopen("pktdump.bin", "w");
#endif

    while(true) {
        uint8_t buf[65536];

        LOG("VIP", 5, sm->getSocket() << ": Waiting for next packet")

            int ret = recvfrom(sm->getSocket(),
                           (char*)buf, sizeof(buf),
                           0,
                           (sockaddr*)&from, &socklen);
#ifdef PKTDUMP
        fwrite(buf, 1, ret, f);
        fflush(f);
#endif

        sm->handlePacket(buf, ret, &from);
    }
};


