Jump to content
  • Advertisement

rigel

Member
  • Content Count

    24
  • Joined

  • Last visited

Community Reputation

401 Neutral

About rigel

  • Rank
    Member

Personal Information

  • Role
    Programmer
    Quality Assurance
  • Interests
    Programming
  1. rigel

    IOCP shutdown design

    I believe its possible without locks, it should do other operations rather than being locked?   true but maybe remote client is flooding some packet that does massive operations and lag server
  2. rigel

    IOCP shutdown design

    CancelIoEx functions sounds good for me nevertheless, it has been rarely used in IOCP examples, why? any performance issues?
  3. rigel

    IOCP shutdown design

    If I understand right, you mean wait operations to be completed and don't post it again. When all is completed, close socket. If so, I don't care operations for complete gracefully because its abortive close. I don't want to call closesocket function simultaneously with any wsa operation(but any operation should be called simultaneously except closesocket, maybe socket handle going to reused), so I want to do something like this:   WSABegin() // will check for socket is closing, if so reads ref count if zero, closes socket here and sets invalid handle else adds ref  WSASend(), WSARecv(), ... any socket required operation WSAEnd() // decrements ref and checks for ref is zero, if so checks for closing flag, sets state closed and calls closesocket   void close() {     InterlockedExc(&m_state, closing)     if (m_ref == 0)     {         closesocket(socket)         socket = INVALID_SOCKET     } }   some complex to explain for me not sure how to implement these operations in atomic way   is that way good?   sounds like I dont know what im doing actually       I'll do another operations when send is completed rather than calling socket functions on send completed, ill read packet from circular queue, format it and send again
  4. rigel

    IOCP shutdown design

    no   sorry for my dumbness, i cant adapt to conversation due to my english weakness its better if you write pseudo codes or any source codes to look out   actually what I want do is, create two threads per cpu for iocp have one request for wsarecv, and one more request for wsasend should be able to abort socket without peer's disconnect without any mutex, critical section or something(only atomic operations)
  5. rigel

    IOCP shutdown design

    No, I don't have. I meant If I receive more than 10 packets in one second from peer (with single outstanding WSARecv), I want to close socket hard immediately.
  6. rigel

    IOCP shutdown design

    If I have packet receive filter (e.g. 10 packets in one second) and peer exceeded it, I want to close socket hard and abort all operations from this user. So how can I do this? Can you recommend me some IOCP servers(to be used in chat apps, mmo, file transfer etc) source codes to dig out? and some libraries to imlement IOCP in painless way?
  7. rigel

    IOCP shutdown design

    This reply is really late, sorry. I wanted to do this for perfect design. But even I ignore this issue, I'll meet similar problem when aborting peer socket.   Assume, we have 2 threads, 1 socket and 2 overlapped operations.   1.Thread closes socket and 2. thread calling wsasend, so maybe socket handle going to be reused (whilst handle can be allocated again) as you described.   1. Thread int ret = WSARecv(sock, ...) if (ret == socket_error) { closesocket(sock); sock = INVALID_SOCKET; }   2. Thread WSASend(sock, ...)   I don't want to use lock since WSARecv and WSASend can be called simultaneously. It would degrade performance, I believe there are ways to synchronize it without locks.     Another question is, If I set linger struct members on=1 and linger=0 on socket, DisconnectEx(TF_REUSE_SOCKET) would do hard close like closesocket does or still graceful?
  8. rigel

    IOCP shutdown design

    I just want to terminate listener socket and accepts because I'll recreate it. May be any risk-free implementation of kernel way?
  9. I have a tcp acceptor class,   pseudo codes class TcpAcceptor {        SOCKET listener;        volatile unsigned int m_pendingAccepts;        void AcceptAsync(OverlappedAccept *ovl)        {               InterlockedIncrement(&m_pendingAccepts);               BOOL cbl = AcceptEx(listener, newSocket()....);               if fails call decrement        }        void Stop()        {               closesocket(m_listener);               m_listener = INVALID_SOCKET               InterlockedWait(&m_pendingAccepts, 0);        } }     TcpAcceptor acp; for (i = 0; i < 100; i++)        acp.AcceptAsync(new overlapped());   acp.Stop();   lets assume, program is executed closesocket function in Stop() (m_listener isnt set to invalid_socket yet), then another thread calls AcceptEx with that old handle (maybe anywhere in program would create new socket and having same handle with listener's handle, so erroneous implement)   I don't want to lock AcceptEx and Stop functions because I don't have any sync problems until I call Stop()   so how can I close listener socket and terminate accepts properly?
  10. No, that's fine. Also, you're likely to see less than the full buffer available to send each time you tick the network generation, unless the user is in a very crowded area. Wait until the next network tick and try again. I suppose if you called on it to transfer zero bytes, it could complete successfully with zero bytes. I would expect that if the connection was closed on the other end, you'd get an error, rather than a completion with zero. If you don't call it with an argument of zero at any time, it's probably OK to treat this as an error condition.     Thank you for your attentive helps!
  11.     <<Yes, multiple WSABUFs (two of them) helps if you want to send the contents of the end-and-beginning at the same time. According to your comment, So, I wanted to send data 4096 byte by 4096. Should I keep that method or any better?   What should I do if WSASend returns with these errors => WSAENOBUFS, WSAEWOULDBLOCK And one more question, can WSASend operation complete with transferred bytes zero in any situation? (like WSARecv does for graceful close)
  12. I'm using TCP. I didn't understand your message completely because of my english weakness but can I result that? Define RingBuffer<n> in user class.   void DoSend() {    WSABUF buf[2];    DWORD bufNum = 0;    if (m_ringBuffer.GetFirstContiguousBytes() > 0)    {        buf[0].buf = m_ringBuffer.GetFirstContiguousPointer();        buf[0].len = m_ringBuffer.GetFirstContigousBytes();        bufNum++;    }      if (m_ringBuffer.GetSecondContiguousBytes() > 0)    {        buf[1].buf = m_ringBuffer.GetSecondContiguousPointer();        buf[1].len = m_ringBuffer.GetSecondContigousBytes();        bufNum++;    }       if (bufNum > 0)          call WSASend(wb, bufNum, &overlapped); }     Build packet, then copy it to ring buffer => m_ringBuffer.write(&packet, size) if WSASend operation is not pending, call DoSend() (If its pending already, It will send it automatically when current is sent) On WSASend completed, m_ringBuffer.Skip(transferredBytes) then call DoSend()   Having multiple wsabufs is good for this?
  13.   <<After your description there is an immediate and enormous design problem: Why do they all need to be at the same place? Can you move them around, put them far enough away that they don't need to be visible? >>I know a game that handles averagely 250 players in same place (they seeing each other), they do attacks, walks, use potions with low-latency.   <<Even if your server in a data center can handle that rate, many of your customers won't have the bandwidth. >>Why? Walk packet would be 67 bytes (including ipv4 + tcp header 40 bytes), If everyone walking per user have to download (67 * 300) = 19 kb packet only. If they do another actions too, I'm sure it won't go more than ~45 kb. However, this size will be reduced since tcp nagling is activate.   But which one is best method to use? I can have agent server(s) if It would be solution, simply gameserver will tell to agentserver what to send to players. (Game <> Agent server communication will be fast, since they are in same LAN) Game which I talked above uses that system, there are 3 or 5 agent servers.
  14. For a mmorpg server, which design should I use? Assume 300 players spawning in same place, they seeing each other. For this we have to send 300 * ( 6(header) + 70(spawn packetpayload) ) bytes of packet (22,2 KB) each user. In total 6,5 MB.   1. struct sendbuffer {      char buffer[4096]      int offset      int size };   (Logic is not written completely or maybe erroneous but you will understand) void writepacket(void *buf, int size) { //check against overflow memcpy(sendbuffer.buffer + offset, buf, size); sendbuffer.size += size; }   When sending, call writepacket(&packet1, 10) call writepacket(&packet2, 55) call WSASend(sendbuffer.buffer, size)   on wsasend io operation completed, offset += transferredBytes (parameter that GetQueuedCompletionStatus gave us) call WSASend(sendbuffer.buffer + offset, size - offset)   2. picking up a fixed-size pool allocator when building packets, just allocate from pool and write in it. There is no copy but it will cost a lot of memory. And queue these allocated packets for user, then send it one by one when WSASend calls completed send next one.   3. Having multiple outstanding calls of WSASend for each packet?   or any better implementation?
  15. rigel

    Packet safety

    An 8-bit version could only have a maximum period of 255 without lag register (at which point it becomes silly to use an 8-bit generator, you can just as well use a larger one then).   What's wrong with the 64-bit multiplicative version with 1024 bits state? You don't have to consume all the bits that come out of it, you know. You can always do xorshiftstar1024() & 0xff  if you only need 8 bits (but 8 bits make a poor sequence number... if I'm malicious, what will I do given a 8-bit sequence number? Right, simply send 256 packets...).   If the server is to "verify" the message, why not add a MAC?   Why maximum period would be 255? Actually I meant by "period" for example if it was 2bit I want it like this (2, 0, 1, 3) next (3, 2, 0, 1) (0, 3, ..) and more. "xorshiftstar1024() & 0xff" can generate same numbers repeatedly.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!