Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab92b89

Browse files
committed
Fixed indentation
1 parent d615972 commit ab92b89

File tree

2 files changed

+63
-63
lines changed

2 files changed

+63
-63
lines changed

src/HTTPServer.cpp

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -232,29 +232,29 @@ void HTTPServer::process() {
232232
*/
233233
void HTTPServer::acceptConnection() {
234234
// Setup new client with prelim address info
235-
sockaddr_in clientAddr;
236-
int clientAddrLen = sizeof(clientAddr);
237-
int clfd = INVALID_SOCKET;
238-
239-
// Accept the pending connection and retrive the client descriptor
240-
clfd = accept(listenSocket, (sockaddr*)&clientAddr, (socklen_t*)&clientAddrLen);
241-
if(clfd == INVALID_SOCKET)
242-
return;
235+
sockaddr_in clientAddr;
236+
int clientAddrLen = sizeof(clientAddr);
237+
int clfd = INVALID_SOCKET;
238+
239+
// Accept the pending connection and retrive the client descriptor
240+
clfd = accept(listenSocket, (sockaddr*)&clientAddr, (socklen_t*)&clientAddrLen);
241+
if(clfd == INVALID_SOCKET)
242+
return;
243243

244244
// Set socket as non blocking
245245
fcntl(clfd, F_SETFL, O_NONBLOCK);
246-
247-
// Instance Client object
248-
Client *cl = new Client(clfd, clientAddr);
249-
246+
247+
// Instance Client object
248+
Client *cl = new Client(clfd, clientAddr);
249+
250250
// Add kqueue event to track the new client socket for READ and WRITE events
251251
updateEvent(clfd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, NULL);
252252
updateEvent(clfd, EVFILT_WRITE, EV_ADD | EV_DISABLE, 0, 0, NULL); // Disabled initially
253-
254-
// Add the client object to the client map
255-
clientMap.insert(std::pair<int, Client*>(clfd, cl));
256-
257-
// Print the client's IP on connect
253+
254+
// Add the client object to the client map
255+
clientMap.insert(std::pair<int, Client*>(clfd, cl));
256+
257+
// Print the client's IP on connect
258258
std::cout << "[" << cl->getClientIP() << "] connected" << std::endl;
259259
}
260260

@@ -314,37 +314,37 @@ void HTTPServer::disconnectClient(Client *cl, bool mapErase) {
314314
* @param data_len Number of bytes waiting to be read
315315
*/
316316
void HTTPServer::readClient(Client *cl, int data_len) {
317-
if (cl == NULL)
318-
return;
317+
if (cl == NULL)
318+
return;
319+
320+
// If the read filter triggered with 0 bytes of data, client may want to disconnect
321+
// Set data_len to the Ethernet max MTU by default
322+
if(data_len <= 0)
323+
data_len = 1400;
319324

320-
// If the read filter triggered with 0 bytes of data, client may want to disconnect
321-
// Set data_len to the Ethernet max MTU by default
322-
if(data_len <= 0)
323-
data_len = 1400;
324-
325325
HTTPRequest* req;
326-
char* pData = new char[data_len];
327-
328-
// Receive data on the wire into pData
329-
/* TODO: Figure out what flags need to be set */
330-
int flags = 0;
331-
ssize_t lenRecv = recv(cl->getSocket(), pData, data_len, flags);
332-
333-
// Determine state of the client socket and act on it
334-
if(lenRecv == 0) {
335-
// Client closed the connection
326+
char* pData = new char[data_len];
327+
328+
// Receive data on the wire into pData
329+
/* TODO: Figure out what flags need to be set */
330+
int flags = 0;
331+
ssize_t lenRecv = recv(cl->getSocket(), pData, data_len, flags);
332+
333+
// Determine state of the client socket and act on it
334+
if(lenRecv == 0) {
335+
// Client closed the connection
336336
std::cout << "[" << cl->getClientIP() << "] has opted to close the connection" << std::endl;
337-
disconnectClient(cl);
338-
} else if(lenRecv < 0) {
339-
// Something went wrong with the connection
340-
// TODO: check perror() for the specific error message
341-
disconnectClient(cl);
342-
} else {
343-
// Data received: Place the data in an HTTPRequest and pass it to handleRequest for processing
337+
disconnectClient(cl);
338+
} else if(lenRecv < 0) {
339+
// Something went wrong with the connection
340+
// TODO: check perror() for the specific error message
341+
disconnectClient(cl);
342+
} else {
343+
// Data received: Place the data in an HTTPRequest and pass it to handleRequest for processing
344344
req = new HTTPRequest((byte*)pData, lenRecv);
345-
handleRequest(cl, req);
345+
handleRequest(cl, req);
346346
delete req;
347-
}
347+
}
348348

349349
delete [] pData;
350350
}
@@ -357,8 +357,8 @@ void HTTPServer::readClient(Client *cl, int data_len) {
357357
* @param avail_bytes Number of bytes available for writing in the send buffer
358358
*/
359359
bool HTTPServer::writeClient(Client* cl, int avail_bytes) {
360-
if (cl == NULL)
361-
return false;
360+
if (cl == NULL)
361+
return false;
362362

363363
int actual_sent = 0; // Actual number of bytes sent as returned by send()
364364
int attempt_sent = 0; // Bytes that we're attempting to send now
@@ -398,7 +398,7 @@ bool HTTPServer::writeClient(Client* cl, int avail_bytes) {
398398
item->setOffset(item->getOffset() + actual_sent);
399399
else
400400
disconnect = true;
401-
401+
402402
//std::cout << "[" << cl->getClientIP() << "] was sent " << actual_sent << " bytes " << std::endl;
403403

404404
// SendQueueItem isnt needed anymore. Dequeue and delete

src/ResourceHost.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,36 +140,36 @@ std::string ResourceHost::generateDirList(std::string path) {
140140
std::string uri = "?";
141141
if(uri_pos != std::string::npos)
142142
uri = path.substr(uri_pos);
143-
143+
144144
std::stringstream ret;
145145
ret << "<html><head><title>" << uri << "</title></head><body>";
146-
147-
DIR *dir;
148-
struct dirent *ent;
149146

150-
dir = opendir(path.c_str());
151-
if(dir == NULL)
152-
return "";
147+
DIR *dir;
148+
struct dirent *ent;
149+
150+
dir = opendir(path.c_str());
151+
if(dir == NULL)
152+
return "";
153153

154154
// Page title, displaying the URI of the directory being listed
155155
ret << "<h1>Index of " << uri << "</h1><hr /><br />";
156-
157-
// Add all files and directories to the return
158-
while((ent = readdir(dir)) != NULL) {
156+
157+
// Add all files and directories to the return
158+
while((ent = readdir(dir)) != NULL) {
159159
// Skip any 'hidden' files (starting with a '.')
160160
if(ent->d_name[0] == '.')
161161
continue;
162-
162+
163163
// Display link to object in directory:
164-
ret << "<a href=\"" << uri << ent->d_name << "\">" << ent->d_name << "</a><br />";
164+
ret << "<a href=\"" << uri << ent->d_name << "\">" << ent->d_name << "</a><br />";
165165
}
166-
167-
// Close the directory
168-
closedir(dir);
166+
167+
// Close the directory
168+
closedir(dir);
169169

170170
ret << "</body></html>";
171-
172-
return ret.str();
171+
172+
return ret.str();
173173
}
174174

175175
/**

0 commit comments

Comments
 (0)