• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Vortez

Question about FD_WRITE

5 posts in this topic

Hi, im aving trouble finding a bug in my program, then it suddently hit me, im not handling the FD_WRITE event in my code. What happen if you send data and the buffer is full? Could that be the cause of my problem? 

 

If so, how should i handle this? What i though is to set a bool variable to true whenever i receive an FD_WRITE event, then set it to false when i receive WSAEWOULDBLOCK, and only send when the variable is true. Is that right?

 

thx

Edited by Vortez
0

Share this post


Link to post
Share on other sites

Assuming you're asking about the socket API, on most system send() blocks until data can be written if in blocking mode, but if in non-blocking mode it returns an error. An exception is if the message is too large for the underlying protocol in which it would return a different error.

0

Share this post


Link to post
Share on other sites

Yea, im using winsock sockets in c++, with WSAAsyncSelect, so im using the windows message system to do my stuff, my socket are not blocking.

Edited by Vortez
0

Share this post


Link to post
Share on other sites

It is totally possible for send() to return less than the full amount of data requested to send.

This is why you typically will want to have a queue of outgoing data, and send from this queue, and only dequeue the data that actually was sent, keeping the rest for the next time around.

 

Also, public service announcement: WSAAsyncSelect() is a very old API, performs very poorly, has known implementation bugs (that Microsoft retains for compatibility reasons,) and is not portable at all. I recommend nobody use it.

0

Share this post


Link to post
Share on other sites

It is totally possible for send() to return less than the full amount of data requested to send.

 

Yea, that part i am aware of it. It's handled properly.

 

 

 


This is why you typically will want to have a queue of outgoing data, and send from this queue, and only dequeue the data that actually was sent, keeping the rest for the next time around.

 

That's actually not a bad idea. I was sending my data by chunks in a loop, so that's might be my problem here. Although im not sure it would help much, gotta think about it.

I need to send my data as fast as possible.

 

 


Also, public service announcement: WSAAsyncSelect() is a very old API, performs very poorly, has known implementation bugs (that Microsoft retains for compatibility reasons,) and is not portable at all. I recommend nobody use it.

 

That part i don't understand. I tried polling the socket with select() in my previous version of my projects, and it's seem that each time i called it, it costed me about 1-15 ms,

so that's why i used WSAAsyncSelect(), and it seem to be a lot faster this way... until it crash for no reason, probably because of the FD_WRITE message i forgot to handle.

 

It also make servers that handle multiples connections much easier to deal with, and require no threads to work, althrough now i think im gonna need one to write.

 

And i can't use blocking sockets, because it could hang my program indefinitely.

 

So, i don't have much other options.

 

Also, portability is not an issue here, im only targeting windows machines.

 

EDIT: That's the old code i was using to poll the socket, specifically, my CanRead() function:  (CanWrite() was pretty much identical)

//-----------------------------------------------------------------------------
// Name : CanRead()
// Desc : Tell if we are ready to read data
//-----------------------------------------------------------------------------
bool CNetBaseEngine::CanRead()
{
	// Setup the timeout for the select() call
	timeval waitd;
	waitd.tv_sec  = 0; // Make select wait up to 1 second for data
	waitd.tv_usec = 1; // and 0 milliseconds.

	// Zero the flags ready for using
	fd_set read_flags;
	FD_ZERO(&read_flags);
	
	// Set the read flag to check the write status of the socket
	FD_SET(m_Socket, &read_flags);

	// Now call select
	int Res = select(m_Socket, &read_flags,(fd_set*)0,(fd_set*)0,&waitd);
	if(Res < 0) {  // If select breaks then pause for 5 seconds
		//Sleep(3);  // then continue
		// Socket not ready to read
		return false;
	}

	// If we are ready to read...
	if(FD_ISSET(m_Socket, &read_flags)){
		// Clear the read flag
		FD_CLR(m_Socket, &read_flags);
		// Socket is ready to read
		return true;
	} else {
		// Socket not ready to read
		return false;
	}
}

The problem is, if i used waitd.tv_usec = 0; i would get errors in my program...

Edited by Vortez
0

Share this post


Link to post
Share on other sites

If you want high performance sockets on Windows, you want to use I/O completion ports with OVERLAPPED I/O.

If you want a nice, portable wrapper on top of this (that uses equally efficient implementations on Linux) then look at boost::asio.

 

Btw: I would be highly surprised if calling select() with a zero timeout would take 1 ms.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0